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
|
:boards-enabled
|
||||||
(u/fmap (fn [board confs]
|
(u/fmap (fn [board confs]
|
||||||
(->> (select-keys confs selecting)
|
(->> (select-keys confs selecting)
|
||||||
(u/fmap (fn [k v]
|
(u/fmap (fn [_ v]
|
||||||
(s/replace v pattern (s/replace board "/" ""))))
|
(s/replace v pattern (s/replace board "/" ""))))
|
||||||
(merge confs)))
|
(merge confs)))
|
||||||
boards))))
|
boards))))
|
||||||
|
|
|
@ -13,10 +13,7 @@
|
||||||
;; 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.core
|
(ns rss-thread-watch.core
|
||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.tools.cli :refer [parse-opts]]
|
||||||
[clojure.edn :as edn]
|
|
||||||
[clojure.string :as s]
|
|
||||||
[clojure.tools.cli :refer [parse-opts]]
|
|
||||||
[ring.adapter.jetty :as jetty]
|
[ring.adapter.jetty :as jetty]
|
||||||
[ring.middleware.params :as rp]
|
[ring.middleware.params :as rp]
|
||||||
[rss-thread-watch.watcher :as watcher]
|
[rss-thread-watch.watcher :as watcher]
|
||||||
|
@ -95,5 +92,3 @@
|
||||||
;; Dont block REPL thread
|
;; Dont block REPL thread
|
||||||
:join? false}))
|
:join? false}))
|
||||||
;; (repl-main)
|
;; (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
|
(ns rss-thread-watch.feed-generator
|
||||||
"Generates feeds for requests"
|
"Generates feeds for requests"
|
||||||
(:require [ring.middleware.params :as rp]
|
(:require [ring.util.response :as response]
|
||||||
[ring.util.response :as response]
|
|
||||||
[clj-rss.core :as rss]
|
[clj-rss.core :as rss]
|
||||||
[clojure.string :as s]
|
[clojure.string :as s]
|
||||||
[rss-thread-watch.watcher :as watcher]
|
[rss-thread-watch.watcher :as watcher]
|
||||||
|
@ -68,8 +67,7 @@
|
||||||
filterable)))
|
filterable)))
|
||||||
|
|
||||||
(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"
|
|
||||||
[filters chod-treshold repeat? board-cache]
|
[filters chod-treshold repeat? board-cache]
|
||||||
(let [{time-of-generation :time
|
(let [{time-of-generation :time
|
||||||
cache :data} board-cache
|
cache :data} board-cache
|
||||||
|
@ -102,7 +100,11 @@
|
||||||
:guid (:guid t)}))
|
:guid (:guid t)}))
|
||||||
|
|
||||||
(defn generate-feed
|
(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]
|
[filters chod-treshold repeat? cache board-config self-link]
|
||||||
(let [items (filter-chod-posts filters chod-treshold repeat? cache)
|
(let [items (filter-chod-posts filters chod-treshold repeat? cache)
|
||||||
head {:title (str "RSS Thread watcher v" conf/VERSION)
|
head {:title (str "RSS Thread watcher v" conf/VERSION)
|
||||||
|
@ -120,8 +122,8 @@
|
||||||
"Handles HTTP requests, returns generated feed
|
"Handles HTTP requests, returns generated feed
|
||||||
|
|
||||||
READS FROM GLOBALS:
|
READS FROM GLOBALS:
|
||||||
rss-thread-watch.watcher.chod-threads-cache
|
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.config/GLOBAL-CONFIG"
|
||||||
[rqst]
|
[rqst]
|
||||||
(try (let [served-filename (get @conf/GLOBAL-CONFIG :served-filename)
|
(try (let [served-filename (get @conf/GLOBAL-CONFIG :served-filename)
|
||||||
{{chod "chod"
|
{{chod "chod"
|
||||||
|
|
|
@ -14,8 +14,7 @@
|
||||||
|
|
||||||
(ns rss-thread-watch.filters
|
(ns rss-thread-watch.filters
|
||||||
"Functions filtering posts"
|
"Functions filtering posts"
|
||||||
(:require [clojure.string :as cs]
|
(:require [clojure.string :as cs])
|
||||||
[rss-thread-watch.utils :as u])
|
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
(defn case-sensitive-filter
|
(defn case-sensitive-filter
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
|
|
||||||
(defn build-cache
|
(defn build-cache
|
||||||
"Build cache of near-death threads so the values don't have to be recalculated on each request."
|
"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)
|
{:time (System/currentTimeMillis)
|
||||||
:data (vec (flatten (map (fn [single-page]
|
:data (vec (flatten (map (fn [single-page]
|
||||||
;; We have to (dec page-number) bcs otherwise we would get the total number of threads
|
;; 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
|
[url] - Url to download data from
|
||||||
[board] - Board to assign cached data to, it's existence is NOT checked here
|
[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
|
[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]
|
[url board starting-page]
|
||||||
;; Todo: surround with try so we can timeout, 40x and other stuff
|
;; Todo: surround with try so we can timeout, 40x and other stuff
|
||||||
(let [catalog (with-open [readr (io/reader url)]
|
(let [catalog (with-open [readr (io/reader url)]
|
||||||
|
@ -82,7 +83,7 @@
|
||||||
;; This will return nill and that fuck everything up
|
;; This will return nill and that fuck everything up
|
||||||
(println "Refreshed cache for " board)
|
(println "Refreshed cache for " board)
|
||||||
(reset! (get @chod-threads-cache 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?
|
(defn board-enabled?
|
||||||
"Checks whether board is enabled in config"
|
"Checks whether board is enabled in config"
|
||||||
|
@ -103,8 +104,7 @@
|
||||||
[board config]
|
[board config]
|
||||||
(let [refresh-rate (* 1000 (get-in config `(:boards-enabled ~board :refresh-rate)))
|
(let [refresh-rate (* 1000 (get-in config `(:boards-enabled ~board :refresh-rate)))
|
||||||
board-catalog-url (get-in config `(:boards-enabled ~board :target))
|
board-catalog-url (get-in config `(:boards-enabled ~board :target))
|
||||||
{data :data
|
{time-downloaded :time
|
||||||
time-downloaded :time
|
|
||||||
:or {time-downloaded 0}
|
:or {time-downloaded 0}
|
||||||
:as board-atom } @(get @chod-threads-cache board)
|
:as board-atom } @(get @chod-threads-cache board)
|
||||||
;; TODO: This also makes it implictly lazy-load -> if disabled make the check here
|
;; TODO: This also makes it implictly lazy-load -> if disabled make the check here
|
||||||
|
|
Loading…
Reference in a new issue