Bugfix update-only-guid and refactor global un-unified access
This commit is contained in:
parent
f1276154ac
commit
2173d6f7fa
1 changed files with 9 additions and 8 deletions
|
@ -13,11 +13,11 @@
|
||||||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
(ns rss-thread-watch.feed-generator
|
(ns rss-thread-watch.feed-generator
|
||||||
"Generates feed for requests"
|
"Generates feeds for requests"
|
||||||
(:require [ring.middleware.params :as rp]
|
(:require [ring.middleware.params :as rp]
|
||||||
[clj-rss.core :as rss]
|
[clj-rss.core :as rss]
|
||||||
[clojure.string :as s]
|
[clojure.string :as s]
|
||||||
[rss-thread-watch.watcher :as cache])
|
[rss-thread-watch.watcher :as watcher])
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,18 +45,18 @@
|
||||||
[thread]
|
[thread]
|
||||||
(assoc thread :guid (format "%d-%.2f"
|
(assoc thread :guid (format "%d-%.2f"
|
||||||
(:no thread)
|
(:no thread)
|
||||||
: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"
|
||||||
[query-vec chod-treshold repeat?]
|
[query-vec chod-treshold repeat? cache]
|
||||||
(let [time-of-generation (System/currentTimeMillis)
|
(let [time-of-generation (System/currentTimeMillis)
|
||||||
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/chod-threads-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/chod-threads-cache cache-start-index) ;Todo: remove that ugly global reference
|
needed-cache-part (subvec cache cache-start-index) ;Todo: remove that ugly global reference
|
||||||
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?
|
||||||
|
@ -82,8 +82,9 @@
|
||||||
:guid (:guid t)}))
|
:guid (:guid t)}))
|
||||||
|
|
||||||
(defn generate-feed
|
(defn generate-feed
|
||||||
[query-vec chod-treshold repeat?]
|
"Generates feed from matching items"
|
||||||
(let [items (filter-chod-posts query-vec chod-treshold repeat?)
|
[query-vec chod-treshold repeat? cache]
|
||||||
|
(let [items (filter-chod-posts query-vec chod-treshold repeat? cache)
|
||||||
head {:title "RSS Thread watcher v0.1"
|
head {:title "RSS Thread watcher v0.1"
|
||||||
: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"
|
||||||
|
|
Loading…
Reference in a new issue