MCPcopy
hub / github.com/tailscale/golink / SaveStats

Method SaveStats

db.go:190–207  ·  view source on GitHub ↗

SaveStats records click stats for links. The provided map includes incremental clicks that have occurred since the last time SaveStats was called.

(stats ClickStats)

Source from the content-addressed store, hash-verified

188// incremental clicks that have occurred since the last time SaveStats
189// was called.
190func (s *SQLiteDB) SaveStats(stats ClickStats) error {
191 s.mu.Lock()
192 defer s.mu.Unlock()
193
194 tx, err := s.db.BeginTx(context.TODO(), nil)
195 if err != nil {
196 return err
197 }
198 now := time.Now().Unix()
199 for short, clicks := range stats {
200 _, err := tx.Exec("INSERT INTO Stats (ID, Created, Clicks) VALUES (?, ?, ?)", linkID(short), now, clicks)
201 if err != nil {
202 tx.Rollback()
203 return err
204 }
205 }
206 return tx.Commit()
207}
208
209// DeleteStats deletes click stats for a link.
210func (s *SQLiteDB) DeleteStats(short string) error {

Callers 2

flushStatsFunction · 0.80

Calls 1

linkIDFunction · 0.85

Tested by 1