Users page is now cached

This commit is contained in:
Eduard Urbach 2017-06-14 17:16:03 +02:00
parent 07702a598f
commit d42f161fdd
6 changed files with 53 additions and 12 deletions

44
jobs/active-users/main.go Normal file
View 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.")
}

View File

@ -31,7 +31,7 @@ func main() {
println(len(cache.IDList)) println(len(cache.IDList))
saveErr := arn.SetObject("Cache", "airing anime", cache) saveErr := arn.DB.Set("Cache", "airing anime", cache)
if saveErr != nil { if saveErr != nil {
color.Red("Error saving airing anime") color.Red("Error saving airing anime")

View File

@ -24,6 +24,8 @@ var avatarOutputs []AvatarOutput
// Main // Main
func main() { func main() {
color.Yellow("Generating user avatars")
// Switch to main directory // Switch to main directory
os.Chdir("../../") os.Chdir("../../")
@ -78,6 +80,8 @@ func main() {
for user := range users { for user := range users {
usersQueue <- user usersQueue <- user
} }
color.Green("Finished.")
} }
// StartWorkers creates multiple workers to handle a user each. // StartWorkers creates multiple workers to handle a user each.

View File

@ -1,7 +1,7 @@
component Layout(content string) component Layout(app *aero.Application, content string)
html(lang="en") html(lang="en")
head head
title notify.moe - Beta title= app.Config.Title
meta(name="viewport", content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes") meta(name="viewport", content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes")
link(rel="manifest", href="/manifest.json") link(rel="manifest", href="/manifest.json")
body body

View File

@ -34,7 +34,7 @@ func main() {
// Layout // Layout
app.Layout = func(ctx *aero.Context, content string) string { app.Layout = func(ctx *aero.Context, content string) string {
return components.Layout(content) return components.Layout(app, content)
} }
// Ajax routes // Ajax routes

View File

@ -2,7 +2,6 @@ package users
import ( import (
"net/http" "net/http"
"sort"
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
@ -11,13 +10,7 @@ import (
// Get ... // Get ...
func Get(ctx *aero.Context) string { func Get(ctx *aero.Context) string {
users, err := arn.FilterUsers(func(user *arn.User) bool { users, err := arn.GetActiveUsersCached()
return user.IsActive() && user.Avatar != ""
})
sort.Slice(users, func(i, j int) bool {
return users[i].Registered < users[j].Registered
})
if err != nil { if err != nil {
return ctx.Error(http.StatusInternalServerError, "Could not fetch user data", err) return ctx.Error(http.StatusInternalServerError, "Could not fetch user data", err)