Fix bug where incorrect time was appended to GUID on param repeat=true

This commit is contained in:
Felisp 2023-12-28 14:39:27 +01:00
parent 7d1e5d9996
commit 2046750fb2
3 changed files with 16 additions and 11 deletions

View file

@ -24,12 +24,12 @@ Right now there is no automated way to generate your feed url but making one by
**** URL parameters **** URL parameters
| Param name | Default value | Can have multiple? | Mandatory? | Short description | | Param name | Values [default] | Can have multiple? | Mandatory? | Short description |
|------------+---------------+--------------------+----------------------+--------------------------------------------------------------------------------------------------| |------------+-------------------------+--------------------+-------------------------+--------------------------------------------------------------------------------------------------|
| board | "mlp" | No | No (not implemented) | Which board to generate feed for, *ONLY* /mlp/ is supported | | board | "mlp" | No | No (not implemented) | Which board to generate feed for, *ONLY* /mlp/ is supported |
| q | nil | Yes | Yes (1 or more) | This string is used to filter threads according to their titles | | q | nil | Yes | Yes (1 or more) | This string is used to filter threads according to their titles |
| chod | 94 | No | No | CHanceOfDeath - will include thread in the feed if it's chance to death i > chod | | chod | 60-99 [94] | No | No | CHanceOfDeath - will include thread in the feed if it's chance to death i > chod |
| repeat | ~false~ | No | No | Whether to make new notification on every server update even when thread doesnt have higher chod | | repeat | true, paranoid, [false] | No | No (partly implemented) | Whether to make new notification on every server update even when thread doesnt have higher chod |
| recreate | ~bool~ | Not implemented | Not implemented | Whether to notify when creation of new thread matching querry is detected (uses 4chans RSS) | | recreate | ~bool~ | Not implemented | Not implemented | Whether to notify when creation of new thread matching querry is detected (uses 4chans RSS) |
**** How to create URL **** How to create URL

View file

@ -49,15 +49,17 @@
(:chod thread)))) (:chod thread))))
(defn filter-chod-posts (defn filter-chod-posts
"Return list of all threads with equal or higher ChoD than requested" "Return list of all threads with equal or higher ChoD than requested
READS FROM GLOBALS: watcher.time-of-cache" ;Todo: best thing would be to add timestamp to cache
[query-vec chod-treshold repeat? cache] [query-vec chod-treshold repeat? cache]
(let [time-of-generation (System/currentTimeMillis) (let [time-of-generation @watcher/time-of-cache
guid-fn (if repeat? (fn [x] (new-guid-always x time-of-generation)) guid-fn (if repeat? (fn [x] (new-guid-always x time-of-generation))
update-only-guid) update-only-guid)
cache-start-index (first (indices (fn [x] (>= (:chod x) chod-treshold)) cache-start-index (first (indices (fn [x] (>= (:chod x) chod-treshold))
cache)) cache))
;; So we don't have to search thru everything we have cached ;; So we don't have to search thru everything we have cached
needed-cache-part (subvec cache cache-start-index) ;Todo: remove that ugly global reference needed-cache-part (subvec cache cache-start-index)
actuall-matches (keep (fn [t] actuall-matches (keep (fn [t]
(let [title (:title t)] (let [title (:title t)]
;; Todo: Man, wouldn't it be cool to know which querry matched the thread? ;; Todo: Man, wouldn't it be cool to know which querry matched the thread?

View file

@ -22,6 +22,8 @@
"Cached vector of threads that have CHanceOfDeath > configured" "Cached vector of threads that have CHanceOfDeath > configured"
(atom [])) (atom []))
(def time-of-cache (atom 0))
(defn process-page (defn process-page
"Procesess every thread in page, leaving only relevant information "Procesess every thread in page, leaving only relevant information
(title no chod)" (title no chod)"
@ -64,4 +66,5 @@
threads-total (+ (* threads-per-page (dec pages-total)) (count (:threads (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] to-index (filter (fn [item]
(<= starting-page (:page item))) catalog)] (<= starting-page (:page item))) catalog)]
(reset! chod-threads-cache (build-cache to-index pages-total threads-per-page threads-total)))) (reset! chod-threads-cache (build-cache to-index pages-total threads-per-page threads-total))
(reset! time-of-cache (System/currentTimeMillis))))