Record statistics on how many bookmarks and words are indexed, and the number of searches performed.

This commit is contained in:
2022-08-20 23:44:47 +09:30
parent c5957e38db
commit ccf373b863
6 changed files with 144 additions and 7 deletions

34
entity/meta.go Normal file
View File

@@ -0,0 +1,34 @@
package entity
import (
"fmt"
"sort"
"time"
)
type DBStats struct {
History map[time.Time]BookmarkInfo
Searches int
}
type BookmarkInfo struct {
Bookmarks int
IndexedWords int
}
func (stats DBStats) String() string {
out := fmt.Sprintf("searches: %d\n", stats.Searches)
dates := []time.Time{}
for k := range stats.History {
dates = append(dates, k)
}
sort.Slice(dates, func(i, j int) bool { return dates[i].Before(dates[j]) })
for _, k := range dates {
out += fmt.Sprintf("%s - %d bookmarks, %d words indexed\n", k, stats.History[k].Bookmarks, stats.History[k].IndexedWords)
}
return out
}