MCPcopy Create free account
hub / github.com/PasarGuard/node / GetUsersStats

Method GetUsersStats

pkg/stats/tracker.go:156–187  ·  view source on GitHub ↗

GetUsersStats returns stats for all public keys (all users)

(_ context.Context, reset bool)

Source from the content-addressed store, hash-verified

154
155// GetUsersStats returns stats for all public keys (all users)
156func (st *Tracker) GetUsersStats(_ context.Context, reset bool) *common.StatResponse {
157 if reset {
158 st.mu.Lock()
159 defer st.mu.Unlock()
160 } else {
161 st.mu.RLock()
162 defer st.mu.RUnlock()
163 }
164
165 response := &common.StatResponse{
166 Stats: make([]*common.Stat, 0, len(st.stats)*2),
167 }
168
169 for key, entry := range st.stats {
170 rx := entry.CurrentRx - entry.BaseRx
171 tx := entry.CurrentTx - entry.BaseTx
172
173 // Skip zero-delta entries
174 stats := buildDeltaStats(entry.Email, key, rx, tx)
175 response.Stats = append(response.Stats, stats...)
176
177 if reset {
178 entry.BaseRx = entry.CurrentRx
179 entry.BaseTx = entry.CurrentTx
180 if entry.IsDeleted {
181 delete(st.stats, key)
182 }
183 }
184 }
185
186 return response
187}
188
189// GetStatsEntries returns stats entries for specific public keys
190func (st *Tracker) GetStatsEntries(keys []string) map[string]*Entry {

Calls 1

buildDeltaStatsFunction · 0.85