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

Method GetStats

pkg/stats/tracker.go:117–153  ·  view source on GitHub ↗

GetStats returns stats for specific public keys (direct map lookup)

(_ context.Context, keys []string, reset bool)

Source from the content-addressed store, hash-verified

115
116// GetStats returns stats for specific public keys (direct map lookup)
117func (st *Tracker) GetStats(_ context.Context, keys []string, reset bool) *common.StatResponse {
118 if reset {
119 st.mu.Lock()
120 defer st.mu.Unlock()
121 } else {
122 st.mu.RLock()
123 defer st.mu.RUnlock()
124 }
125
126 response := &common.StatResponse{
127 Stats: make([]*common.Stat, 0),
128 }
129
130 for _, key := range keys {
131 entry, exists := st.stats[key]
132 if !exists {
133 continue
134 }
135
136 rx := entry.CurrentRx - entry.BaseRx
137 tx := entry.CurrentTx - entry.BaseTx
138
139 // Skip zero-delta entries
140 stats := buildDeltaStats(entry.Email, key, rx, tx)
141 response.Stats = append(response.Stats, stats...)
142
143 if reset {
144 entry.BaseRx = entry.CurrentRx
145 entry.BaseTx = entry.CurrentTx
146 if entry.IsDeleted {
147 delete(st.stats, key)
148 }
149 }
150 }
151
152 return response
153}
154
155// GetUsersStats returns stats for all public keys (all users)
156func (st *Tracker) GetUsersStats(_ context.Context, reset bool) *common.StatResponse {

Callers

nothing calls this directly

Calls 1

buildDeltaStatsFunction · 0.85

Tested by

no test coverage detected