From bffc1589c214cf30ad44017a4aad8a6d0ff6e344 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Sat, 23 Jul 2022 12:47:31 -0400 Subject: [PATCH] emojy: add a threshold for stats page --- plugins/emojy/emojy.go | 6 +++--- plugins/emojy/web.go | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/emojy/emojy.go b/plugins/emojy/emojy.go index 93b7d9c..4222518 100644 --- a/plugins/emojy/emojy.go +++ b/plugins/emojy/emojy.go @@ -207,12 +207,12 @@ func InvertEmojyList(emojy map[string]string) map[string]string { return out } -func (p *EmojyPlugin) allCounts() (map[string][]EmojyCount, error) { +func (p *EmojyPlugin) allCounts(threshold int) (map[string][]EmojyCount, error) { out := map[string][]EmojyCount{} onServerList := InvertEmojyList(p.b.GetEmojiList(true)) - q := `select emojy, count(observed) as count from emojyLog group by emojy order by count desc` + q := `select emojy, count(observed) as count from emojyLog group by emojy having count(observed) > ? order by count desc` result := []EmojyCount{} - err := p.db.Select(&result, q) + err := p.db.Select(&result, q, threshold) if err != nil { return nil, err } diff --git a/plugins/emojy/web.go b/plugins/emojy/web.go index b3cc94b..691d9bb 100644 --- a/plugins/emojy/web.go +++ b/plugins/emojy/web.go @@ -44,7 +44,8 @@ func (p *EmojyPlugin) handlePage(file string) func(w http.ResponseWriter, r *htt } func (p *EmojyPlugin) handleAll(w http.ResponseWriter, r *http.Request) { - emojy, err := p.allCounts() + threshold := p.c.GetInt("emojy.statthreshold", 1) + emojy, err := p.allCounts(threshold) if err != nil { w.WriteHeader(500) log.Error().Err(err).Msgf("handleAll")