diff --git a/jobs/jobs.go b/jobs/jobs.go index 276f5f7c..9f3a86d1 100644 --- a/jobs/jobs.go +++ b/jobs/jobs.go @@ -31,12 +31,12 @@ var jobs = map[string]time.Duration{ "popular-anime": 20 * time.Minute, "avatars": 30 * time.Minute, "twist": 1 * time.Hour, + "search-index": 2 * time.Hour, "sync-shoboi": 8 * time.Hour, "refresh-episodes": 10 * time.Hour, "refresh-track-titles": 10 * time.Hour, "refresh-osu": 12 * time.Hour, "sync-anime": 12 * time.Hour, - "search-index": 12 * time.Hour, } func main() { diff --git a/jobs/search-index/search-index.go b/jobs/search-index/search-index.go index 273e6807..01cb9ada 100644 --- a/jobs/search-index/search-index.go +++ b/jobs/search-index/search-index.go @@ -12,7 +12,12 @@ import ( func main() { color.Yellow("Updating search index") - flow.Parallel(updateAnimeIndex, updateUserIndex) + flow.Parallel( + updateAnimeIndex, + updateUserIndex, + updatePostIndex, + updateThreadIndex, + ) color.Green("Finished.") } @@ -71,10 +76,7 @@ func updateUserIndex() { // Users userStream, err := arn.StreamUsers() - - if err != nil { - panic(err) - } + arn.PanicOnError(err) for user := range userStream { if user.HasNick() { @@ -86,8 +88,42 @@ func updateUserIndex() { // Save in database err = arn.DB.Set("SearchIndex", "User", userSearchIndex) - - if err != nil { - panic(err) - } + arn.PanicOnError(err) +} + +func updatePostIndex() { + postSearchIndex := arn.NewSearchIndex() + + // Users + postStream, err := arn.StreamPosts() + arn.PanicOnError(err) + + for post := range postStream { + postSearchIndex.TextToID[strings.ToLower(post.Text)] = post.ID + } + + fmt.Println(len(postSearchIndex.TextToID), "posts") + + // Save in database + err = arn.DB.Set("SearchIndex", "Post", postSearchIndex) + arn.PanicOnError(err) +} + +func updateThreadIndex() { + threadSearchIndex := arn.NewSearchIndex() + + // Users + threadStream, err := arn.StreamThreads() + arn.PanicOnError(err) + + for thread := range threadStream { + threadSearchIndex.TextToID[strings.ToLower(thread.Title)] = thread.ID + threadSearchIndex.TextToID[strings.ToLower(thread.Text)] = thread.ID + } + + fmt.Println(len(threadSearchIndex.TextToID)/2, "threads") + + // Save in database + err = arn.DB.Set("SearchIndex", "Thread", threadSearchIndex) + arn.PanicOnError(err) } diff --git a/middleware/Firewall.go b/middleware/Firewall.go index 1929ec8a..0594e57c 100644 --- a/middleware/Firewall.go +++ b/middleware/Firewall.go @@ -11,7 +11,7 @@ import ( const requestThreshold = 10 -var ipToStats = cache.New(30*time.Minute, 15*time.Minute) +var ipToStats = cache.New(15*time.Minute, 15*time.Minute) // IPStats captures the statistics for a single IP. type IPStats struct { diff --git a/pages/animelist/animelist.scarlet b/pages/animelist/animelist.scarlet index 8d2d609a..e0a97e10 100644 --- a/pages/animelist/animelist.scarlet +++ b/pages/animelist/animelist.scarlet @@ -13,9 +13,7 @@ .anime-list-item-name flex 1 - white-space nowrap - text-overflow ellipsis - overflow hidden + clip-long-text .anime-list-item-episodes horizontal diff --git a/pages/dashboard/dashboard.scarlet b/pages/dashboard/dashboard.scarlet index 16566790..ca979fcf 100644 --- a/pages/dashboard/dashboard.scarlet +++ b/pages/dashboard/dashboard.scarlet @@ -1,8 +1,6 @@ .schedule-item-link, .schedule-item-title - white-space nowrap - text-overflow ellipsis - overflow hidden + clip-long-text .schedule-item-link horizontal diff --git a/pages/search/search.go b/pages/search/search.go index c86995f4..67298913 100644 --- a/pages/search/search.go +++ b/pages/search/search.go @@ -8,11 +8,13 @@ import ( const maxUsers = 6 * 6 const maxAnime = 5 * 6 +const maxPosts = 3 +const maxThreads = 3 // Get search page. func Get(ctx *aero.Context) string { term := ctx.Query("q") - userResults, animeResults := arn.Search(term, maxUsers, maxAnime) - return ctx.HTML(components.SearchResults(term, userResults, animeResults)) + userResults, animeResults, postResults, threadResults := arn.Search(term, maxUsers, maxAnime, maxPosts, maxThreads) + return ctx.HTML(components.SearchResults(term, userResults, animeResults, postResults, threadResults)) } diff --git a/pages/search/search.pixy b/pages/search/search.pixy index f7269231..ca32fef6 100644 --- a/pages/search/search.pixy +++ b/pages/search/search.pixy @@ -1,4 +1,4 @@ -component SearchResults(term string, users []*arn.User, animeResults []*arn.Anime) +component SearchResults(term string, users []*arn.User, animeResults []*arn.Anime, postResults []*arn.Post, threadResults []*arn.Thread) h1.page-title= "Search: " + term .widgets @@ -32,9 +32,26 @@ component SearchResults(term string, users []*arn.User, animeResults []*arn.Anim .widget h3.widget-title Icon("comment") - span Forums + span Forum - p.no-search-results.mountable Forums search coming soon. + if len(postResults) == 0 && len(threadResults) == 0 + p.no-search-results.mountable No posts found. + else + each thread in threadResults + .mountable(data-mountable-type="forum") + .forum-search-result + a.forum-search-result-title.ajax(href=thread.Link())= thread.Title + if thread.Author().HasNick() + .forum-search-result-author= thread.Author().Nick + .forum-search-result-sample= thread.Text + + each post in postResults + .mountable(data-mountable-type="forum") + .forum-search-result + a.forum-search-result-title.ajax(href=post.Link(), data-mountable-type="forum")= post.Thread().Title + if post.Author().HasNick() + .forum-search-result-author= post.Author().Nick + .forum-search-result-sample= post.Text .widget h3.widget-title diff --git a/pages/search/search.scarlet b/pages/search/search.scarlet index 2f0d315d..9a609128 100644 --- a/pages/search/search.scarlet +++ b/pages/search/search.scarlet @@ -2,5 +2,21 @@ width 55px !important height 78px !important +.forum-search-result + horizontal + +.forum-search-result-title + flex 1 + clip-long-text + +.forum-search-result-author + text-align right + opacity 0.5 + +.forum-search-result-sample + clip-long-text + margin-bottom 1rem + opacity 0.8 + .no-search-results text-align left \ No newline at end of file diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 66c663a3..316e6638 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -488,11 +488,9 @@ export class AnimeNotifier { let time = 0 let start = Date.now() let maxTime = start + maxDelay - let mutations = [] - let mountableTypes = { - general: start - } + let mountableTypes = new Map() + let mountableTypeMutations = new Map>() let collection = document.getElementsByClassName(className) @@ -506,43 +504,49 @@ export class AnimeNotifier { let element = collection.item(i) as HTMLElement let type = element.dataset.mountableType || "general" - if(type in mountableTypes) { - time = mountableTypes[type] += delay + if(mountableTypes.has(type)) { + time = mountableTypes.get(type) + delay + mountableTypes.set(type, time) } else { - time = mountableTypes[type] = start + time = start + mountableTypes.set(type, time) + mountableTypeMutations.set(type, []) } if(time > maxTime) { time = maxTime } - mutations.push({ + mountableTypeMutations.get(type).push({ element, time }) } - let mutationIndex = 0 + for(let mountableType of mountableTypeMutations.keys()) { + let mutations = mountableTypeMutations.get(mountableType) + let mutationIndex = 0 - let updateBatch = () => { - let now = Date.now() + let updateBatch = () => { + let now = Date.now() - for(; mutationIndex < mutations.length; mutationIndex++) { - let mutation = mutations[mutationIndex] + for(; mutationIndex < mutations.length; mutationIndex++) { + let mutation = mutations[mutationIndex] - if(mutation.time > now) { - break + if(mutation.time > now) { + break + } + + func(mutation.element) } - func(mutation.element) + if(mutationIndex < mutations.length) { + window.requestAnimationFrame(updateBatch) + } } - if(mutationIndex < mutations.length) { - window.requestAnimationFrame(updateBatch) - } + window.requestAnimationFrame(updateBatch) } - - window.requestAnimationFrame(updateBatch) } diff(url: string) { diff --git a/scripts/Diff.ts b/scripts/Diff.ts index d450c0d9..50afac15 100644 --- a/scripts/Diff.ts +++ b/scripts/Diff.ts @@ -23,9 +23,7 @@ export class Diff { } Diff.rootContainer.innerHTML = html.replace("", "") - console.log(aRoot.getElementsByTagName("body")[0]) - console.log(Diff.rootContainer.getElementsByTagName("body")[0]) - Diff.childNodes(aRoot.getElementsByTagName("body")[0], Diff.rootContainer.getElementsByTagName("body")[0]) + Diff.childNodes(aRoot, Diff.rootContainer) } // childNodes diffs the child nodes of 2 given elements and applies DOM mutations.