Users page is now cached
This commit is contained in:
44
jobs/active-users/main.go
Normal file
44
jobs/active-users/main.go
Normal file
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
func main() {
|
||||
color.Yellow("Caching list of active users")
|
||||
|
||||
cache := arn.ListOfIDs{}
|
||||
|
||||
// Filter out active users with an avatar
|
||||
users, err := arn.FilterUsers(func(user *arn.User) bool {
|
||||
return user.IsActive() && user.Avatar != ""
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Sort
|
||||
sort.Slice(users, func(i, j int) bool {
|
||||
return users[i].Registered < users[j].Registered
|
||||
})
|
||||
|
||||
// Add users to list
|
||||
for _, user := range users {
|
||||
cache.IDList = append(cache.IDList, user.ID)
|
||||
}
|
||||
|
||||
fmt.Println(len(cache.IDList), "users")
|
||||
|
||||
err = arn.DB.Set("Cache", "active users", cache)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
color.Green("Finished.")
|
||||
}
|
@ -31,7 +31,7 @@ func main() {
|
||||
|
||||
println(len(cache.IDList))
|
||||
|
||||
saveErr := arn.SetObject("Cache", "airing anime", cache)
|
||||
saveErr := arn.DB.Set("Cache", "airing anime", cache)
|
||||
|
||||
if saveErr != nil {
|
||||
color.Red("Error saving airing anime")
|
||||
|
@ -24,6 +24,8 @@ var avatarOutputs []AvatarOutput
|
||||
|
||||
// Main
|
||||
func main() {
|
||||
color.Yellow("Generating user avatars")
|
||||
|
||||
// Switch to main directory
|
||||
os.Chdir("../../")
|
||||
|
||||
@ -78,6 +80,8 @@ func main() {
|
||||
for user := range users {
|
||||
usersQueue <- user
|
||||
}
|
||||
|
||||
color.Green("Finished.")
|
||||
}
|
||||
|
||||
// StartWorkers creates multiple workers to handle a user each.
|
||||
|
Reference in New Issue
Block a user