From 84b3e11b8ef46a53f6e77e611fda4ded198767f2 Mon Sep 17 00:00:00 2001 From: Felisp Date: Thu, 15 Aug 2024 17:29:56 +0200 Subject: [PATCH] Implement repeat=paranoid --- project.clj | 2 +- src/rss_thread_watch/core.clj | 2 +- src/rss_thread_watch/feed_generator.clj | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/project.clj b/project.clj index 55ad16b..2abe787 100644 --- a/project.clj +++ b/project.clj @@ -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" :url "http://example.com/FIXME" :license {:name "AGPL-3.0-only" diff --git a/src/rss_thread_watch/core.clj b/src/rss_thread_watch/core.clj index 7799a10..7b7058f 100644 --- a/src/rss_thread_watch/core.clj +++ b/src/rss_thread_watch/core.clj @@ -23,7 +23,7 @@ [rss-thread-watch.utils :as u]) (:gen-class)) -(def VERSION "0.4.0") +(def VERSION "0.4.1") ;; Internal default config (def CONFIG-DEFAULT diff --git a/src/rss_thread_watch/feed_generator.clj b/src/rss_thread_watch/feed_generator.clj index 7c6c15d..33760e5 100644 --- a/src/rss_thread_watch/feed_generator.clj +++ b/src/rss_thread_watch/feed_generator.clj @@ -36,6 +36,15 @@ "-" 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 "Generates new GUID for feed item ONLY if the threads ChoD increased @@ -53,8 +62,10 @@ (let [{time-of-generation :time cache :data} board-cache - guid-fn (if repeat? (fn [x] (new-guid-always x time-of-generation)) - update-only-guid) + guid-fn (case repeat? + "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)) ;; So we don't have to search thru everything we have cached @@ -87,7 +98,7 @@ "Generates feed from matching items" [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" :feed-url "https://tools.treebrary.org/thread-watcher/feed.xml" :description "RSS based thread watcher"} @@ -102,13 +113,14 @@ rss-thread-watch.watcher.GLOBAL-CONFIG" ;TODO: Update if it really reads from there anymore [rqst] (try (let [{{chod "chod" - board "board" :or {chod "94" - board (get @watcher/GLOBAL-CONFIG :default-board)} + board "board" + repeat? "repeat" :or {chod "94" + board (get @watcher/GLOBAL-CONFIG :default-board) + repeat? false} :as prms} :params uri :uri} rqst qrs (prms "q") queries (if (vector? qrs) qrs [qrs]) ; to always return vector - repeat? (prms "repeat") real-chod (if-let [ch (or (and (vector? chod) (first chod)) chod)]