MCPcopy Create free account
hub / github.com/cortexproject/cortex / PurgeInactiveUsers

Method PurgeInactiveUsers

pkg/util/users/active_user.go:56–95  ·  view source on GitHub ↗

PurgeInactiveUsers removes users that were last active before given deadline, and returns removed users.

(deadline int64)

Source from the content-addressed store, hash-verified

54
55// PurgeInactiveUsers removes users that were last active before given deadline, and returns removed users.
56func (m *ActiveUsers) PurgeInactiveUsers(deadline int64) []string {
57 // Find inactive users with read-lock.
58 m.mu.RLock()
59 inactive := make([]string, 0, len(m.timestamps))
60
61 for userID, ts := range m.timestamps {
62 if ts.Load() <= deadline {
63 inactive = append(inactive, userID)
64 }
65 }
66 m.mu.RUnlock()
67
68 if len(inactive) == 0 {
69 return nil
70 }
71
72 // Cleanup inactive users.
73 for ix := 0; ix < len(inactive); {
74 userID := inactive[ix]
75 deleted := false
76
77 m.mu.Lock()
78 u := m.timestamps[userID]
79 if u != nil && u.Load() <= deadline {
80 delete(m.timestamps, userID)
81 deleted = true
82 }
83 m.mu.Unlock()
84
85 if deleted {
86 // keep it in the output
87 ix++
88 } else {
89 // not really inactive, remove it from output
90 inactive = append(inactive[:ix], inactive[ix+1:]...)
91 }
92 }
93
94 return inactive
95}
96
97func (m *ActiveUsers) ActiveUsers(deadline int64) []string {
98 m.mu.RLock()

Callers 4

TestActiveUserFunction · 0.95
iterationMethod · 0.80

Calls 1

LoadMethod · 0.80

Tested by 3

TestActiveUserFunction · 0.76