Improved dashboard performance

This commit is contained in:
2017-06-29 20:52:30 +02:00
parent f4703fdd5f
commit dca96b317e
6 changed files with 60 additions and 27 deletions

View File

@ -0,0 +1,49 @@
package main
import (
"github.com/animenotifier/arn"
"github.com/fatih/color"
)
const maxEntries = 5
func main() {
color.Yellow("Caching list of forum activities")
posts, err := arn.AllPosts()
arn.PanicOnError(err)
threads, err := arn.AllThreads()
arn.PanicOnError(err)
arn.SortPostsLatestFirst(posts)
arn.SortThreadsLatestFirst(threads)
posts = arn.FilterPostsWithUniqueThreads(posts, maxEntries)
postPostables := arn.ToPostables(posts)
threadPostables := arn.ToPostables(threads)
allPostables := append(postPostables, threadPostables...)
arn.SortPostablesLatestFirst(allPostables)
cachedPostables := arn.FilterPostablesWithUniqueThreads(allPostables, maxEntries)
cache := &arn.ListOfMappedIDs{}
for _, postable := range cachedPostables {
cache.Append(postable.Type(), postable.ID())
}
// // Debug log
// arn.PrettyPrint(cache)
// // Try to resolve
// for _, r := range arn.ToPostables(cache.Resolve()) {
// color.Green(r.Title())
// }
arn.PanicOnError(arn.DB.Set("Cache", "forum activity", cache))
color.Green("Finished.")
}

View File

@ -24,6 +24,7 @@ var colorPool = []*color.Color{
var jobs = map[string]time.Duration{
"active-users": 1 * time.Minute,
"forum-activity": 1 * time.Minute,
"avatars": 1 * time.Hour,
"refresh-track-titles": 10 * time.Hour,
"sync-anime": 12 * time.Hour,