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{
|
var jobs = map[string]time.Duration{
|
||||||
"active-users": 1 * time.Minute,
|
"active-users": 1 * time.Minute,
|
||||||
|
"forum-activity": 1 * time.Minute,
|
||||||
"avatars": 1 * time.Hour,
|
"avatars": 1 * time.Hour,
|
||||||
"refresh-track-titles": 10 * time.Hour,
|
"refresh-track-titles": 10 * time.Hour,
|
||||||
"sync-anime": 12 * time.Hour,
|
"sync-anime": 12 * time.Hour,
|
||||||
|
@ -29,8 +29,7 @@ func Get(ctx *aero.Context) string {
|
|||||||
|
|
||||||
// Render the dashboard.
|
// Render the dashboard.
|
||||||
func dashboard(ctx *aero.Context) string {
|
func dashboard(ctx *aero.Context) string {
|
||||||
var forumPosts []arn.Postable
|
var forumActivity []arn.Postable
|
||||||
var forumThreads []arn.Postable
|
|
||||||
var userList interface{}
|
var userList interface{}
|
||||||
var followingList []*arn.User
|
var followingList []*arn.User
|
||||||
var soundTracks []*arn.SoundTrack
|
var soundTracks []*arn.SoundTrack
|
||||||
@ -39,21 +38,7 @@ func dashboard(ctx *aero.Context) string {
|
|||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
|
|
||||||
flow.Parallel(func() {
|
flow.Parallel(func() {
|
||||||
posts, err := arn.AllPosts()
|
forumActivity, _ = arn.GetForumActivityCached()
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forumPosts = arn.ToPostables(posts)
|
|
||||||
}, func() {
|
|
||||||
threads, err := arn.AllThreads()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
forumThreads = arn.ToPostables(threads)
|
|
||||||
}, func() {
|
}, func() {
|
||||||
animeList, err := arn.GetAnimeList(user)
|
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))
|
return ctx.HTML(components.Dashboard(upcomingEpisodes, forumActivity, soundTracks, followingList))
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string {
|
|||||||
}, func() {
|
}, func() {
|
||||||
threads = viewUser.Threads()
|
threads = viewUser.Threads()
|
||||||
|
|
||||||
arn.SortThreadsByDate(threads)
|
arn.SortThreadsLatestFirst(threads)
|
||||||
|
|
||||||
if len(threads) > maxPosts {
|
if len(threads) > maxPosts {
|
||||||
threads = threads[:maxPosts]
|
threads = threads[:maxPosts]
|
||||||
|
@ -18,7 +18,7 @@ func GetThreadsByUser(ctx *aero.Context) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
threads := user.Threads()
|
threads := user.Threads()
|
||||||
arn.SortThreadsByDate(threads)
|
arn.SortThreadsLatestFirst(threads)
|
||||||
|
|
||||||
return ctx.HTML(components.ThreadList(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 endTime = (h <= 9 ? "0" + h : h) + ":" + (m <= 9 ? "0" + m : m)
|
||||||
|
|
||||||
let dayDifference = Math.round((startDate.getTime() - now.getTime()) / oneDay)
|
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 dayInfo = dayNames[startDate.getDay()] + ", " + monthNames[startDate.getMonth()] + " " + startDate.getDate()
|
||||||
|
|
||||||
let airingVerb = "will be airing"
|
let airingVerb = "will be airing"
|
||||||
|
Loading…
Reference in New Issue
Block a user