Improved dashboard performance
This commit is contained in:
parent
f4703fdd5f
commit
dca96b317e
49
jobs/forum-activity/main.go
Normal file
49
jobs/forum-activity/main.go
Normal 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.")
|
||||
}
|
@ -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,
|
||||
|
@ -29,8 +29,7 @@ func Get(ctx *aero.Context) string {
|
||||
|
||||
// Render the dashboard.
|
||||
func dashboard(ctx *aero.Context) string {
|
||||
var forumPosts []arn.Postable
|
||||
var forumThreads []arn.Postable
|
||||
var forumActivity []arn.Postable
|
||||
var userList interface{}
|
||||
var followingList []*arn.User
|
||||
var soundTracks []*arn.SoundTrack
|
||||
@ -39,21 +38,7 @@ func dashboard(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
flow.Parallel(func() {
|
||||
posts, err := arn.AllPosts()
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
forumPosts = arn.ToPostables(posts)
|
||||
}, func() {
|
||||
threads, err := arn.AllThreads()
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
forumThreads = arn.ToPostables(threads)
|
||||
forumActivity, _ = arn.GetForumActivityCached()
|
||||
}, func() {
|
||||
animeList, err := arn.GetAnimeList(user)
|
||||
|
||||
@ -121,13 +106,5 @@ func dashboard(ctx *aero.Context) string {
|
||||
}
|
||||
})
|
||||
|
||||
forumActivity := append(forumPosts, forumThreads...)
|
||||
|
||||
sort.Slice(forumActivity, func(i, j int) bool {
|
||||
return forumActivity[i].Created() > forumActivity[j].Created()
|
||||
})
|
||||
|
||||
forumActivity = arn.FilterPostablesWithUniqueThreads(forumActivity, maxPosts)
|
||||
|
||||
return ctx.HTML(components.Dashboard(upcomingEpisodes, forumActivity, soundTracks, followingList))
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string {
|
||||
}, func() {
|
||||
threads = viewUser.Threads()
|
||||
|
||||
arn.SortThreadsByDate(threads)
|
||||
arn.SortThreadsLatestFirst(threads)
|
||||
|
||||
if len(threads) > maxPosts {
|
||||
threads = threads[:maxPosts]
|
||||
|
@ -18,7 +18,7 @@ func GetThreadsByUser(ctx *aero.Context) string {
|
||||
}
|
||||
|
||||
threads := user.Threads()
|
||||
arn.SortThreadsByDate(threads)
|
||||
arn.SortThreadsLatestFirst(threads)
|
||||
|
||||
return ctx.HTML(components.ThreadList(threads))
|
||||
}
|
||||
|
@ -100,6 +100,12 @@ export class AnimeNotifier {
|
||||
let endTime = (h <= 9 ? "0" + h : h) + ":" + (m <= 9 ? "0" + m : m)
|
||||
|
||||
let dayDifference = Math.round((startDate.getTime() - now.getTime()) / oneDay)
|
||||
|
||||
if(isNaN(dayDifference)) {
|
||||
element.style.opacity = "0"
|
||||
continue
|
||||
}
|
||||
|
||||
let dayInfo = dayNames[startDate.getDay()] + ", " + monthNames[startDate.getMonth()] + " " + startDate.getDate()
|
||||
|
||||
let airingVerb = "will be airing"
|
||||
|
Loading…
Reference in New Issue
Block a user