From 674f0447fc10f733f5eda0f153779fe0ecdf6c6c Mon Sep 17 00:00:00 2001 From: Felisp Date: Fri, 22 Dec 2023 23:30:47 +0100 Subject: [PATCH] Fixed bug where off-by-one was giving incorrect result of ChoD calculation --- src/rss_thread_watch/watcher.clj | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/rss_thread_watch/watcher.clj b/src/rss_thread_watch/watcher.clj index 037fc24..e6b33db 100644 --- a/src/rss_thread_watch/watcher.clj +++ b/src/rss_thread_watch/watcher.clj @@ -38,10 +38,7 @@ :chod (* 100 (float (/ index threads-total)))})))))) (defn build-cache - "Build cache of near-death threads so the values don't have to be recalculated on each request. - - Bugs: There is probably off-by-one somewhere in the calculation because thread at position 150 doesn't - have 100% chance of death which is weird, however, 99.333% is considered close enough for now" + "Build cache of near-death threads so the values don't have to be recalculated on each request." [pages-to-index pages-total threads-per-page threads-total] (vec (flatten (map (fn [single-page] ;; We have to (dec page-number) bcs otherwise we would get the total number of threads @@ -64,7 +61,7 @@ ;; universal calculation for total number of threads: ;; (pages-total-1) * threadsPerPage + threadsOnLastpage ;;accounts for boards which have stickied threads making them have 11pages threads-per-page (count (:threads (first catalog))) - threads-total (+ (* threads-per-page (dec pages-total) (count (last catalog)))) ;; Todo: Yeah, maybe this calculation could be refactored into let + threads-total (+ (* threads-per-page (dec pages-total)) (count (:threads (last catalog)))) ;; Todo: Yeah, maybe this calculation could be refactored into let to-index (filter (fn [item] (<= starting-page (:page item))) catalog)] (reset! chod-threads-cache (build-cache to-index pages-total threads-per-page threads-total))))