| @@ -798,11 +798,27 @@ func (s *Service) rebuildAuthMaintenanceIndex(snapshot []*coreauth.Auth, authDir · 797 unmodified lines |
| 798 | 798 | } |
| 799 | 799 | |
| 800 | 800 | func (s *Service) rebuildAuthMaintenanceIndexLocked(snapshot []*coreauth.Auth, authDir string) { |
| 801 | | − s.maintenanceAuthIDsByPath = make(map[string]map[string]struct{}) |
| 802 | | − s.maintenanceAuthPathByID = make(map[string]string) |
| 801 | + idsByPath := make(map[string]map[string]struct{}) |
| 802 | + pathByID := make(map[string]string) |
| 803 | 803 | for _, auth := range snapshot { |
| 804 | | − s.indexAuthMaintenanceAuthLocked(auth, authDir) |
| 804 | + if auth == nil { |
| 805 | + continue |
| 806 | + } |
| 807 | + id := strings.TrimSpace(auth.ID) |
| 808 | + if id == "" { |
| 809 | + continue |
| 810 | + } |
| 811 | + path := resolveAuthFilePath(auth, authDir) |
| 812 | + if path == "" { |
| 813 | + continue |
| 814 | + } |
| 815 | + if idsByPath[path] == nil { |
| 816 | + idsByPath[path] = make(map[string]struct{}) |
| 817 | + } |
| 818 | + idsByPath[path][id] = struct{}{} |
| 819 | + pathByID[id] = path |
| 805 | 820 | } |
| 821 | + s.replaceAuthMaintenanceIndexLocked(idsByPath, pathByID) |
| 806 | 822 | } |
| 807 | 823 | |
| 808 | 824 | func (s *Service) indexAuthMaintenanceAuth(auth *coreauth.Auth) { |
| @@ -910,6 +926,27 @@ func (s *Service) authMaintenanceIDsForPath(path, authDir string) []string { · 101 unmodified lines |
| 910 | 926 | return out |
| 911 | 927 | } |
| 912 | 928 | |
| 929 | +func (s *Service) replaceAuthMaintenanceIndex(idsByPath map[string]map[string]struct{}, pathByID map[string]string) { |
| 930 | + if s == nil { |
| 931 | + return |
| 932 | + } |
| 933 | + s.ensureAuthMaintenanceQueue() |
| 934 | + s.maintenanceMu.Lock() |
| 935 | + defer s.maintenanceMu.Unlock() |
| 936 | + s.replaceAuthMaintenanceIndexLocked(idsByPath, pathByID) |
| 937 | +} |
| 938 | + |
| 939 | +func (s *Service) replaceAuthMaintenanceIndexLocked(idsByPath map[string]map[string]struct{}, pathByID map[string]string) { |
| 940 | + if idsByPath == nil { |
| 941 | + idsByPath = make(map[string]map[string]struct{}) |
| 942 | + } |
| 943 | + if pathByID == nil { |
| 944 | + pathByID = make(map[string]string) |
| 945 | + } |
| 946 | + s.maintenanceAuthIDsByPath = idsByPath |
| 947 | + s.maintenanceAuthPathByID = pathByID |
| 948 | +} |
| 949 | + |
| 913 | 950 | func (s *Service) snapshotAuthMaintenanceConfig() (config.AuthMaintenanceConfig, string) { |
| 914 | 951 | if s == nil { |
| 915 | 952 | return config.AuthMaintenanceConfig{ |
| @@ -946,8 +983,9 @@ func (s *Service) scanAuthMaintenanceCandidates(now time.Time, cfg config.AuthMa · 30 unmodified lines |
| 946 | 983 | return nil |
| 947 | 984 | } |
| 948 | 985 | snapshot := s.coreManager.List() |
| 949 | | − s.rebuildAuthMaintenanceIndex(snapshot, authDir) |
| 950 | 986 | grouped := make(map[string]authMaintenanceCandidate) |
| 987 | + idsByPath := make(map[string]map[string]struct{}) |
| 988 | + pathByID := make(map[string]string) |
| 951 | 989 | for _, auth := range snapshot { |
| 952 | 990 | path := resolveAuthFilePath(auth, authDir) |
| 953 | 991 | if path == "" { |
| @@ -961,7 +999,15 @@ func (s *Service) scanAuthMaintenanceCandidates(now time.Time, cfg config.AuthMa · 7 unmodified lines |
| 961 | 999 | } |
| 962 | 1000 | } |
| 963 | 1001 | if auth != nil && strings.TrimSpace(auth.ID) != "" { |
| 964 | | − group.IDs = append(group.IDs, strings.TrimSpace(auth.ID)) |
| 1002 | + id := strings.TrimSpace(auth.ID) |
| 1003 | + if idsByPath[path] == nil { |
| 1004 | + idsByPath[path] = make(map[string]struct{}) |
| 1005 | + } |
| 1006 | + if _, exists := idsByPath[path][id]; !exists { |
| 1007 | + idsByPath[path][id] = struct{}{} |
| 1008 | + group.IDs = append(group.IDs, id) |
| 1009 | + } |
| 1010 | + pathByID[id] = path |
| 965 | 1011 | } |
| 966 | 1012 | if group.Reason == "" { |
| 967 | 1013 | if reason, ok := authEligibleForMaintenanceDelete(auth, nil, cfg, now); ok { |
| @@ -970,6 +1016,7 @@ func (s *Service) scanAuthMaintenanceCandidates(now time.Time, cfg config.AuthMa · 2 unmodified lines |
| 970 | 1016 | } |
| 971 | 1017 | grouped[path] = group |
| 972 | 1018 | } |
| 1019 | + s.replaceAuthMaintenanceIndex(idsByPath, pathByID) |
| 973 | 1020 | |
| 974 | 1021 | candidates := make([]authMaintenanceCandidate, 0, len(grouped)) |
| 975 | 1022 | for _, candidate := range grouped { |