mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-19 04:40:52 +08:00
perf(management): optimize auth lookup in PatchAuthFileStatus
Use GetByID() for O(1) map lookup first, falling back to iteration only for FileName matching. Consistent with pattern in disableAuth().
This commit is contained in:
@@ -777,13 +777,17 @@ func (h *Handler) PatchAuthFileStatus(c *gin.Context) {
|
|||||||
|
|
||||||
// Find auth by name or ID
|
// Find auth by name or ID
|
||||||
var targetAuth *coreauth.Auth
|
var targetAuth *coreauth.Auth
|
||||||
|
if auth, ok := h.authManager.GetByID(name); ok {
|
||||||
|
targetAuth = auth
|
||||||
|
} else {
|
||||||
auths := h.authManager.List()
|
auths := h.authManager.List()
|
||||||
for _, auth := range auths {
|
for _, auth := range auths {
|
||||||
if auth.FileName == name || auth.ID == name {
|
if auth.FileName == name {
|
||||||
targetAuth = auth
|
targetAuth = auth
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if targetAuth == nil {
|
if targetAuth == nil {
|
||||||
c.JSON(http.StatusNotFound, gin.H{"error": "auth file not found"})
|
c.JSON(http.StatusNotFound, gin.H{"error": "auth file not found"})
|
||||||
|
|||||||
Reference in New Issue
Block a user