From 555d1339a86483b5ac728328964cbfb9fea0c0d7 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Wed, 9 Nov 2022 13:15:30 -0800 Subject: [PATCH] golink: truncate clicks slice after sorting previously, the 200 links included in the "popular links" list were non-deterministic (though those 200 were sorted). Now, always shows the top 200. --- golink.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/golink.go b/golink.go index 21633c2..c068e3b 100644 --- a/golink.go +++ b/golink.go @@ -221,15 +221,15 @@ func serveHome(w http.ResponseWriter, short string) { } stats.mu.Unlock() - if len(clicks) > 200 { - clicks = clicks[:200] - } sort.Slice(clicks, func(i, j int) bool { if clicks[i].NumClicks != clicks[j].NumClicks { return clicks[i].NumClicks > clicks[j].NumClicks } return clicks[i].Short < clicks[j].Short }) + if len(clicks) > 200 { + clicks = clicks[:200] + } homeTmpl.Execute(w, homeData{ Short: short,