From 8bee2f4e102e47df3aa377550076af64079bf15d Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 23 Jun 2017 16:53:07 +0200 Subject: [PATCH] Improved user sort --- jobs/active-users/main.go | 10 +++++++++- patches/add-last-seen/main.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 patches/add-last-seen/main.go diff --git a/jobs/active-users/main.go b/jobs/active-users/main.go index db0bfe96..8c520285 100644 --- a/jobs/active-users/main.go +++ b/jobs/active-users/main.go @@ -24,7 +24,15 @@ func main() { // Sort sort.Slice(users, func(i, j int) bool { - return users[i].LastSeen > users[j].LastSeen + if users[i].LastSeen < users[j].LastSeen { + return false + } + + if users[i].LastSeen > users[j].LastSeen { + return true + } + + return users[i].Registered > users[j].Registered }) // Add users to list diff --git a/patches/add-last-seen/main.go b/patches/add-last-seen/main.go new file mode 100644 index 00000000..ca8fcc3c --- /dev/null +++ b/patches/add-last-seen/main.go @@ -0,0 +1,29 @@ +package main + +import ( + "github.com/animenotifier/arn" +) + +func main() { + // Get a stream of all users + allUsers, err := arn.AllUsers() + + if err != nil { + panic(err) + } + + // Iterate over the stream + for user := range allUsers { + if user.LastSeen != "" { + continue + } + + user.LastSeen = user.LastLogin + + if user.LastSeen == "" { + user.LastSeen = user.Registered + } + + user.Save() + } +}