Implement repeat=paranoid

This commit is contained in:
Felisp 2024-08-15 17:29:56 +02:00
parent 5679cee18b
commit 84b3e11b8e
3 changed files with 20 additions and 8 deletions

View file

@ -1,4 +1,4 @@
(defproject rss-thread-watch "0.4.0-SNAPSHOT" (defproject rss-thread-watch "0.4.1-SNAPSHOT"
:description "RSS based thread watcher" :description "RSS based thread watcher"
:url "http://example.com/FIXME" :url "http://example.com/FIXME"
:license {:name "AGPL-3.0-only" :license {:name "AGPL-3.0-only"

View file

@ -23,7 +23,7 @@
[rss-thread-watch.utils :as u]) [rss-thread-watch.utils :as u])
(:gen-class)) (:gen-class))
(def VERSION "0.4.0") (def VERSION "0.4.1")
;; Internal default config ;; Internal default config
(def CONFIG-DEFAULT (def CONFIG-DEFAULT

View file

@ -36,6 +36,15 @@
"-" "-"
time))) time)))
(defn new-guid-paranoid
"Generate unique GUID on EVERY request to the feed.
Usefull for when you really don't want thread to die.
By making new GUID on every request you can be sure that what you're
seeing in your feed reader isn't cached"
[thread]
(new-guid-always thread (System/currentTimeMillis)))
(defn update-only-guid (defn update-only-guid
"Generates new GUID for feed item ONLY if the threads ChoD increased "Generates new GUID for feed item ONLY if the threads ChoD increased
@ -53,8 +62,10 @@
(let [{time-of-generation :time (let [{time-of-generation :time
cache :data} board-cache cache :data} board-cache
guid-fn (if repeat? (fn [x] (new-guid-always x time-of-generation)) guid-fn (case repeat?
update-only-guid) "paranoid" new-guid-paranoid
"true" (fn [x] (new-guid-always x time-of-generation))
update-only-guid)
cache-start-index (first (ut/indices (fn [x] (>= (:chod x) chod-treshold)) cache-start-index (first (ut/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
@ -87,7 +98,7 @@
"Generates feed from matching items" "Generates feed from matching items"
[query-vec chod-treshold repeat? cache] [query-vec chod-treshold repeat? cache]
(let [items (filter-chod-posts query-vec chod-treshold repeat? cache) (let [items (filter-chod-posts query-vec chod-treshold repeat? cache)
head {:title "RSS Thread watcher v0.4" ;TODO: hardcoded string here, remake to reference to config.clj head {:title "RSS Thread watcher v0.4.1" ;TODO: hardcoded string here, remake to reference to config.clj
:link "https://tools.treebrary.org/thread-watcher/feed.xml" :link "https://tools.treebrary.org/thread-watcher/feed.xml"
:feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml"
:description "RSS based thread watcher"} :description "RSS based thread watcher"}
@ -102,13 +113,14 @@
rss-thread-watch.watcher.GLOBAL-CONFIG" ;TODO: Update if it really reads from there anymore rss-thread-watch.watcher.GLOBAL-CONFIG" ;TODO: Update if it really reads from there anymore
[rqst] [rqst]
(try (let [{{chod "chod" (try (let [{{chod "chod"
board "board" :or {chod "94" board "board"
board (get @watcher/GLOBAL-CONFIG :default-board)} repeat? "repeat" :or {chod "94"
board (get @watcher/GLOBAL-CONFIG :default-board)
repeat? false}
:as prms} :params :as prms} :params
uri :uri} rqst uri :uri} rqst
qrs (prms "q") qrs (prms "q")
queries (if (vector? qrs) qrs [qrs]) ; to always return vector queries (if (vector? qrs) qrs [qrs]) ; to always return vector
repeat? (prms "repeat")
real-chod (if-let [ch (or (and (vector? chod) real-chod (if-let [ch (or (and (vector? chod)
(first chod)) (first chod))
chod)] chod)]