Cleanup suggested by clj-kondo And update GLOBALS access info
This commit is contained in:
parent
4b7a6e66d8
commit
7c1720cd4e
5 changed files with 18 additions and 22 deletions
|
@ -72,7 +72,7 @@
|
|||
:boards-enabled
|
||||
(u/fmap (fn [board confs]
|
||||
(->> (select-keys confs selecting)
|
||||
(u/fmap (fn [k v]
|
||||
(u/fmap (fn [_ v]
|
||||
(s/replace v pattern (s/replace board "/" ""))))
|
||||
(merge confs)))
|
||||
boards))))
|
||||
|
|
|
@ -13,10 +13,7 @@
|
|||
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
(ns rss-thread-watch.core
|
||||
(:require [clojure.java.io :as io]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.string :as s]
|
||||
[clojure.tools.cli :refer [parse-opts]]
|
||||
(:require [clojure.tools.cli :refer [parse-opts]]
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[ring.middleware.params :as rp]
|
||||
[rss-thread-watch.watcher :as watcher]
|
||||
|
@ -95,5 +92,3 @@
|
|||
;; Dont block REPL thread
|
||||
:join? false}))
|
||||
;; (repl-main)
|
||||
;; Single cache update for repl
|
||||
;; (watcher/update-thread-cache! (:target CONFIG) (:starting-page CONFIG))
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
(ns rss-thread-watch.feed-generator
|
||||
"Generates feeds for requests"
|
||||
(:require [ring.middleware.params :as rp]
|
||||
[ring.util.response :as response]
|
||||
(:require [ring.util.response :as response]
|
||||
[clj-rss.core :as rss]
|
||||
[clojure.string :as s]
|
||||
[rss-thread-watch.watcher :as watcher]
|
||||
|
@ -68,8 +67,7 @@
|
|||
filterable)))
|
||||
|
||||
(defn filter-chod-posts
|
||||
"Return list of all threads with equal or higher ChoD than requested
|
||||
READS FROM GLOBALS: watcher.time-of-cache"
|
||||
"Return list of all threads with equal or higher ChoD than requested"
|
||||
[filters chod-treshold repeat? board-cache]
|
||||
(let [{time-of-generation :time
|
||||
cache :data} board-cache
|
||||
|
@ -102,7 +100,11 @@
|
|||
:guid (:guid t)}))
|
||||
|
||||
(defn generate-feed
|
||||
"Generates feed from matching items"
|
||||
"Generates feed from matching items
|
||||
|
||||
READS FROM GLOBALS:
|
||||
rss-thread-watch.config/VERSION
|
||||
rss-thread-watch.config/GLOBAL_CONFIG"
|
||||
[filters chod-treshold repeat? cache board-config self-link]
|
||||
(let [items (filter-chod-posts filters chod-treshold repeat? cache)
|
||||
head {:title (str "RSS Thread watcher v" conf/VERSION)
|
||||
|
@ -120,8 +122,8 @@
|
|||
"Handles HTTP requests, returns generated feed
|
||||
|
||||
READS FROM GLOBALS:
|
||||
rss-thread-watch.watcher.chod-threads-cache
|
||||
rss-thread-watch.config.GLOBAL-CONFIG" ;TODO: Update if it really reads from there anymore
|
||||
rss-thread-watch.watcher/chod-threads-cache
|
||||
rss-thread-watch.config/GLOBAL-CONFIG"
|
||||
[rqst]
|
||||
(try (let [served-filename (get @conf/GLOBAL-CONFIG :served-filename)
|
||||
{{chod "chod"
|
||||
|
|
|
@ -14,8 +14,7 @@
|
|||
|
||||
(ns rss-thread-watch.filters
|
||||
"Functions filtering posts"
|
||||
(:require [clojure.string :as cs]
|
||||
[rss-thread-watch.utils :as u])
|
||||
(:require [clojure.string :as cs])
|
||||
(:gen-class))
|
||||
|
||||
(defn case-sensitive-filter
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
(defn build-cache
|
||||
"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]
|
||||
[pages-to-index threads-per-page threads-total]
|
||||
{:time (System/currentTimeMillis)
|
||||
:data (vec (flatten (map (fn [single-page]
|
||||
;; We have to (dec page-number) bcs otherwise we would get the total number of threads
|
||||
|
@ -64,8 +64,9 @@
|
|||
[url] - Url to download data from
|
||||
[board] - Board to assign cached data to, it's existence is NOT checked here
|
||||
[starting-page] - From which page consider threads to be fit for near-death cache
|
||||
THIS FUNCTION WRITES TO chod-threads-cache
|
||||
Returns :data part of [board] cache"
|
||||
Returns :data part of [board] cache
|
||||
THIS FUNCTION WRITES TO:
|
||||
rss-thread-watch.watcher/chod-threads-cache"
|
||||
[url board starting-page]
|
||||
;; Todo: surround with try so we can timeout, 40x and other stuff
|
||||
(let [catalog (with-open [readr (io/reader url)]
|
||||
|
@ -82,7 +83,7 @@
|
|||
;; This will return nill and that fuck everything up
|
||||
(println "Refreshed cache for " board)
|
||||
(reset! (get @chod-threads-cache board)
|
||||
(build-cache to-index pages-total threads-per-page threads-total))))
|
||||
(build-cache to-index threads-per-page threads-total))))
|
||||
|
||||
(defn board-enabled?
|
||||
"Checks whether board is enabled in config"
|
||||
|
@ -103,8 +104,7 @@
|
|||
[board config]
|
||||
(let [refresh-rate (* 1000 (get-in config `(:boards-enabled ~board :refresh-rate)))
|
||||
board-catalog-url (get-in config `(:boards-enabled ~board :target))
|
||||
{data :data
|
||||
time-downloaded :time
|
||||
{time-downloaded :time
|
||||
:or {time-downloaded 0}
|
||||
:as board-atom } @(get @chod-threads-cache board)
|
||||
;; TODO: This also makes it implictly lazy-load -> if disabled make the check here
|
||||
|
|
Loading…
Reference in a new issue