diff --git a/jobs/forum-activity/main.go b/jobs/forum-activity/main.go new file mode 100644 index 00000000..3c2bb808 --- /dev/null +++ b/jobs/forum-activity/main.go @@ -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.") +} diff --git a/jobs/main.go b/jobs/main.go index 9368da98..ebb8afa1 100644 --- a/jobs/main.go +++ b/jobs/main.go @@ -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, diff --git a/pages/dashboard/dashboard.go b/pages/dashboard/dashboard.go index f71591c4..1b68a404 100644 --- a/pages/dashboard/dashboard.go +++ b/pages/dashboard/dashboard.go @@ -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)) } diff --git a/pages/profile/profile.go b/pages/profile/profile.go index c69c5e57..aaa39dfe 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -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] diff --git a/pages/profile/threads.go b/pages/profile/threads.go index 29cdd457..5a0a8e9e 100644 --- a/pages/profile/threads.go +++ b/pages/profile/threads.go @@ -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)) } diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index c861a741..039b0fc7 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -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"