From 2f6004d74a8cf5706526e836f4da3c13b69e3174 Mon Sep 17 00:00:00 2001 From: Aldino Kemal Date: Mon, 19 Jan 2026 20:05:37 +0700 Subject: [PATCH] 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(). --- internal/api/handlers/management/auth_files.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/api/handlers/management/auth_files.go b/internal/api/handlers/management/auth_files.go index 005bc7b9..77988fea 100644 --- a/internal/api/handlers/management/auth_files.go +++ b/internal/api/handlers/management/auth_files.go @@ -777,11 +777,15 @@ func (h *Handler) PatchAuthFileStatus(c *gin.Context) { // Find auth by name or ID var targetAuth *coreauth.Auth - auths := h.authManager.List() - for _, auth := range auths { - if auth.FileName == name || auth.ID == name { - targetAuth = auth - break + if auth, ok := h.authManager.GetByID(name); ok { + targetAuth = auth + } else { + auths := h.authManager.List() + for _, auth := range auths { + if auth.FileName == name { + targetAuth = auth + break + } } }