Cleanup
This commit is contained in:
49
jobs/forum-activity/forum-activity.go
Normal file
49
jobs/forum-activity/forum-activity.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.")
|
||||
}
|
Reference in New Issue
Block a user