瀏覽代碼

fix: kondo lint and add worker aliases

also fixed location of a test ns and fixed some inconsistent worker
aliases
Gabriel Horner 1 年之前
父節點
當前提交
073f37dcc7

+ 7 - 0
.clj-kondo/config.edn

@@ -119,10 +119,17 @@
              frontend.util.text text-util
              frontend.util.url url-util
              frontend.util.thingatpt thingatpt
+             frontend.worker.pipeline worker-pipeline
+             frontend.worker.util worker-util
+             frontend.worker.state worker-state
+             frontend.worker.handler.page worker-page
+             frontend.worker.handler.page.rename worker-page-rename
+             frontend.worker.handler.file.util wfu
              lambdaisland.glogi log
              logseq.common.path path
              logseq.common.graph common-graph
              logseq.common.config common-config
+             logseq.db ldb
              logseq.db.frontend.property db-property
              logseq.db.frontend.property.type db-property-type
              logseq.db.frontend.property.util db-property-util

+ 28 - 28
src/main/frontend/db_worker.cljs

@@ -13,7 +13,7 @@
             [cljs-bean.core :as bean]
             [frontend.worker.search :as search]
             [logseq.db.sqlite.util :as sqlite-util]
-            [frontend.worker.state :as state]
+            [frontend.worker.state :as worker-state]
             [frontend.worker.file :as file]
             [logseq.db :as ldb]
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
@@ -25,10 +25,10 @@
             [frontend.worker.util :as worker-util]
             [frontend.worker.handler.page.rename :as worker-page-rename]))
 
-(defonce *sqlite state/*sqlite)
-(defonce *sqlite-conns state/*sqlite-conns)
-(defonce *datascript-conns state/*datascript-conns)
-(defonce *opfs-pools state/*opfs-pools)
+(defonce *sqlite worker-state/*sqlite)
+(defonce *sqlite-conns worker-state/*sqlite-conns)
+(defonce *datascript-conns worker-state/*datascript-conns)
+(defonce *opfs-pools worker-state/*opfs-pools)
 
 (defn- get-pool-name
   [graph-name]
@@ -36,7 +36,7 @@
 
 (defn- <get-opfs-pool
   [graph]
-  (or (state/get-opfs-pool graph)
+  (or (worker-state/get-opfs-pool graph)
       (p/let [^js pool (.installOpfsSAHPoolVfs @*sqlite #js {:name (get-pool-name graph)
                                                              :initialCapacity 20})]
         (swap! *opfs-pools assoc graph pool)
@@ -72,7 +72,7 @@
 (defn upsert-addr-content!
   "Upsert addr+data-seq"
   [repo data delete-addrs]
-  (let [^Object db (state/get-sqlite-conn repo)]
+  (let [^Object db (worker-state/get-sqlite-conn repo)]
     (assert (some? db) "sqlite db not exists")
     (.transaction db (fn [tx]
                        (doseq [item data]
@@ -85,7 +85,7 @@
 
 (defn restore-data-from-addr
   [repo addr]
-  (let [^Object db (state/get-sqlite-conn repo)]
+  (let [^Object db (worker-state/get-sqlite-conn repo)]
     (assert (some? db) "sqlite db not exists")
     (when-let [content (-> (.exec db #js {:sql "select content from kvs where addr = ?"
                                           :bind #js [addr]
@@ -116,7 +116,7 @@
   (swap! *datascript-conns dissoc repo)
   (when db (.close db))
   (when search (.close search))
-  (when-let [^js pool (state/get-opfs-pool repo)]
+  (when-let [^js pool (worker-state/get-opfs-pool repo)]
     (.releaseAccessHandles pool))
   (swap! *opfs-pools dissoc repo))
 
@@ -133,7 +133,7 @@
 
 (defn- create-or-open-db!
   [repo]
-  (when-not (state/get-sqlite-conn repo)
+  (when-not (worker-state/get-sqlite-conn repo)
     (p/let [^js pool (<get-opfs-pool repo)
             capacity (.getCapacity pool)
             _ (when (zero? capacity)   ; file handle already releases since pool will be initialized only once
@@ -197,7 +197,7 @@
 
 (defn- get-search-db
   [repo]
-  (state/get-sqlite-conn repo {:search? true}))
+  (worker-state/get-sqlite-conn repo {:search? true}))
 
 
 #_:clj-kondo/ignore
@@ -217,7 +217,7 @@
 
   (init
    [_this rtc-ws-url]
-   (reset! state/*rtc-ws-url rtc-ws-url)
+   (reset! worker-state/*rtc-ws-url rtc-ws-url)
    (init-sqlite-module!))
 
   (listDB
@@ -249,20 +249,20 @@
 
   (getMaxTx
    [_this repo]
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (:max-tx @conn)))
 
   (q [_this repo inputs-str]
      "Datascript q"
-     (when-let [conn (state/get-datascript-conn repo)]
+     (when-let [conn (worker-state/get-datascript-conn repo)]
        (let [inputs (edn/read-string inputs-str)]
          (let [result (apply d/q (first inputs) @conn (rest inputs))]
            (bean/->js result)))))
 
   (transact
    [_this repo tx-data tx-meta context]
-   (when repo (state/set-db-latest-tx-time! repo))
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when repo (worker-state/set-db-latest-tx-time! repo))
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (try
        (let [tx-data (if (string? tx-data)
                        (edn/read-string tx-data)
@@ -273,7 +273,7 @@
              context (if (string? context)
                        (edn/read-string context)
                        context)
-             _ (when context (state/set-context! context))
+             _ (when context (worker-state/set-context! context))
              tx-meta' (if (:new-graph? tx-meta)
                         tx-meta
                         (cond-> tx-meta
@@ -298,7 +298,7 @@
 
   (getInitialData
    [_this repo]
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (->> (sqlite-common-db/get-initial-data @conn)
           dt/write-transit-str)))
 
@@ -311,7 +311,7 @@
 
   (releaseAccessHandles
    [_this repo]
-   (when-let [^js pool (state/get-opfs-pool repo)]
+   (when-let [^js pool (worker-state/get-opfs-pool repo)]
      (.releaseAccessHandles pool)))
 
   (dbExists
@@ -355,23 +355,23 @@
 
   (search-build-blocks-indice
    [this repo]
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (search/build-blocks-indice repo @conn)))
 
   (search-build-pages-indice
    [this repo]
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (search/build-blocks-indice repo @conn)))
 
   (page-search
    [this repo q limit]
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (search/page-search repo @conn q limit)))
 
   (page-rename
    [this repo old-name new-name]
-   (when-let [conn (state/get-datascript-conn repo)]
-     (let [config (state/get-config repo)
+   (when-let [conn (worker-state/get-datascript-conn repo)]
+     (let [config (worker-state/get-config repo)
            result (worker-page-rename/rename! repo conn config old-name new-name)]
        (bean/->js {:result result}))))
 
@@ -387,13 +387,13 @@
   (sync-app-state
    [this new-state-str]
    (let [new-state (edn/read-string new-state-str)]
-     (state/set-new-state! new-state)
+     (worker-state/set-new-state! new-state)
      nil))
 
   ;; RTC
   (rtc-start
    [this repo token]
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (rtc-core/<start-rtc repo conn token)
      nil))
 
@@ -421,7 +421,7 @@
 
   (rtc-upload-graph
    [this repo token]
-   (when-let [conn (state/get-datascript-conn repo)]
+   (when-let [conn (worker-state/get-datascript-conn repo)]
      (async/go
        (try
          (let [state (<! (rtc-core/<init-state repo token false))]
@@ -485,7 +485,7 @@
   "web worker entry"
   []
   (let [^js obj (DBWorker.)]
-    (state/set-worker-object! obj)
+    (worker-state/set-worker-object! obj)
     (file/<ratelimit-file-writes!)
     (Comlink/expose obj)))
 

+ 0 - 1
src/main/frontend/extensions/tldraw.cljs

@@ -19,7 +19,6 @@
             [frontend.state :as state]
             [frontend.util :as util]
             [goog.object :as gobj]
-            [goog.functions :refer [debounce]]
             [promesa.core :as p]
             [rum.core :as rum]
             [frontend.ui :as ui]

+ 0 - 1
src/main/frontend/handler/events.cljs

@@ -54,7 +54,6 @@
             [frontend.handler.db-based.property.util :as db-pu]
             [frontend.handler.file-based.property.util :as property-util]
             [frontend.handler.property :as property-handler]
-            [frontend.handler.whiteboard :as whiteboard-handler]
             [frontend.handler.web.nfs :as nfs-handler]
             [frontend.handler.code :as code-handler]
             [frontend.mobile.core :as mobile]

+ 0 - 1
src/main/frontend/handler/whiteboard.cljs

@@ -7,7 +7,6 @@
             [frontend.handler.editor :as editor-handler]
             [frontend.handler.route :as route-handler]
             [frontend.handler.property.util :as pu]
-            [frontend.modules.editor.undo-redo :as history]
             [frontend.state :as state]
             [frontend.config :as config]
             [frontend.storage :as storage]

+ 3 - 3
src/main/frontend/search/fuzzy.cljs

@@ -2,7 +2,7 @@
   "fuzzy search"
   (:require [clojure.string :as string]
             [cljs-bean.core :as bean]
-            [frontend.worker.util :as util]))
+            [frontend.worker.util :as worker-util]))
 
 (def MAX-STRING-LENGTH 1000.0)
 
@@ -59,12 +59,12 @@
 (defn fuzzy-search
   [data query & {:keys [limit extract-fn]
                  :or {limit 20}}]
-  (let [query (util/search-normalize query true)]
+  (let [query (worker-util/search-normalize query true)]
     (->> (take limit
                (sort-by :score (comp - compare)
                         (filter #(< 0 (:score %))
                                 (for [item data]
                                   (let [s (str (if extract-fn (extract-fn item) item))]
                                     {:data item
-                                     :score (score query (util/search-normalize s true))})))))
+                                     :score (score query (worker-util/search-normalize s true))})))))
          (map :data))))

+ 6 - 6
src/main/frontend/worker/db/fix.cljs

@@ -6,7 +6,7 @@
   (:require [datascript.core :as d]
             [cljs.pprint :as pprint]
             [logseq.db :as ldb]
-            [frontend.worker.util :as util]))
+            [frontend.worker.util :as worker-util]))
 
 (defn- fix-parent-broken-chain
   [db parent-id]
@@ -27,10 +27,10 @@
                                                :block/left (:db/id (:block/left b))}) blocks)}]
             (prn :debug "Broken chain:")
             (pprint/pprint error-data)
-            (util/post-message :notification
-                               (pr-str [[:div
-                                         (str "Broken chain detected:\n" error-data)]
-                                        :error])))
+            (worker-util/post-message :notification
+                                      (pr-str [[:div
+                                                (str "Broken chain detected:\n" error-data)]
+                                               :error])))
           (let [first-child-id (:db/id (ldb/get-by-parent-&-left db parent-id parent-id))
                 *ids (atom children-ids)
                 sections (loop [sections []]
@@ -111,7 +111,7 @@
   [db conflicts]
   (when (seq conflicts)
     (prn :debug "Parent left id conflicts:")
-    (util/post-message :notification (pr-str [[:div
+    (worker-util/post-message :notification (pr-str [[:div
                                                (str "Parent-left conflicts detected:\n"
                                                     conflicts)]
                                               :error])))

+ 4 - 4
src/main/frontend/worker/file.cljs

@@ -12,7 +12,7 @@
             [datascript.core :as d]
             [logseq.db :as ldb]
             [malli.core :as m]
-            [frontend.worker.state :as state]
+            [frontend.worker.state :as worker-state]
             [goog.object :as gobj]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.common.util :as common-util]))
@@ -68,7 +68,7 @@
                                   (contains? #{:delete-blocks :move-blocks} outliner-op))]
     (when (or (>= blocks-count 1) blocks-just-deleted?)
       (if (and (or (> blocks-count 500) whiteboard?)
-               (not (state/tx-idle? repo {:diff 3000})))
+               (not (worker-state/tx-idle? repo {:diff 3000})))
         (async/put! file-writes-chan [repo page-db-id outliner-op (tc/to-long (t/now)) request-id])
         (let [pull-keys (if whiteboard? whiteboard-blocks-pull-keys-with-persisted-ids '[*])
               blocks (ldb/get-page-blocks @conn (:block/name page-block) {:pull-keys pull-keys})
@@ -121,7 +121,7 @@
                           (fn [col]
                             (when (seq col)
                               (let [repo (ffirst col)
-                                    conn (state/get-datascript-conn repo)]
+                                    conn (worker-state/get-datascript-conn repo)]
                                 (if conn
-                                  (write-files! conn col (state/get-context))
+                                  (write-files! conn col (worker-state/get-context))
                                   (js/console.error (str "DB is not found for ") repo)))))))

+ 5 - 5
src/main/frontend/worker/file/core.cljs

@@ -7,7 +7,7 @@
             [datascript.core :as d]
             [logseq.db :as ldb]
             [frontend.worker.date :as worker-date]
-            [frontend.worker.util :as util]))
+            [frontend.worker.util :as worker-util]))
 
 (defonce *writes (atom {}))
 (defonce *request-id (atom 0))
@@ -166,10 +166,10 @@
                      (let [files [[file-path new-content]]]
                        (when (seq files)
                          (let [page-id (:db/id page-block)]
-                           (util/post-message :write-files (pr-str {:request-id request-id
-                                                                    :page-id page-id
-                                                                    :repo repo
-                                                                    :files files}))
+                           (worker-util/post-message :write-files (pr-str {:request-id request-id
+                                                                           :page-id page-id
+                                                                           :repo repo
+                                                                           :files files}))
                            :sent)))))
                  ;; In e2e tests, "card" page in db has no :file/path
                  (js/console.error "File path from page-block is not valid" page-block tree))]

+ 1 - 1
src/main/frontend/worker/handler/page/rename.cljs

@@ -92,7 +92,7 @@
 (declare rename-page-aux)
 
 (defn- based-merge-pages!
-  [repo conn config from-page-name to-page-name {:keys [old-name new-name persist-op?]}]
+  [repo conn config from-page-name to-page-name {:keys [old-name new-name]}]
   (when (and (ldb/page-exists? @conn from-page-name)
              (ldb/page-exists? @conn to-page-name)
              (not= from-page-name to-page-name))

+ 2 - 2
src/main/frontend/worker/rtc/db_listener.cljs

@@ -7,7 +7,7 @@
             [datascript.core :as d]
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
             [frontend.worker.state :as worker-state]
-            [frontend.worker.pipeline :as pipeline]
+            [frontend.worker.pipeline :as worker-pipeline]
             [frontend.worker.search :as search]
             [frontend.worker.util :as worker-util]
             [promesa.core :as p]
@@ -208,7 +208,7 @@
   (d/listen! conn :sync-db
              (fn [{:keys [tx-meta] :as tx-report}]
                (let [{:keys [pipeline-replace?]} tx-meta
-                     result (pipeline/invoke-hooks repo conn tx-report (worker-state/get-context))
+                     result (worker-pipeline/invoke-hooks repo conn tx-report (worker-state/get-context))
                      tx-report' (or (:tx-report result) tx-report)]
                  (when-not pipeline-replace?
                    (let [data (pr-str

+ 3 - 3
src/main/frontend/worker/rtc/full_upload_download_graph.cljs

@@ -11,7 +11,7 @@
             [frontend.worker.rtc.op-mem-layer :as op-mem-layer]
             [frontend.worker.rtc.ws :refer [<send!]]
             [logseq.db.frontend.schema :as db-schema]
-            [frontend.worker.state :as state]
+            [frontend.worker.state :as worker-state]
             [promesa.core :as p]
             [frontend.worker.util :as worker-util]))
 
@@ -120,11 +120,11 @@
    (let [{:keys [t blocks]} all-blocks
          blocks* (replace-db-id-with-temp-id blocks)
          blocks-with-page-id (fill-block-fields blocks*)
-         ^js worker-obj (:worker/object @state/*state)
+         ^js worker-obj (:worker/object @worker-state/*state)
          work (p/do!
                (.createOrOpenDB worker-obj repo)
                (.exportDB worker-obj repo)
-               (.transact worker-obj repo blocks-with-page-id nil (state/get-context))
+               (.transact worker-obj repo blocks-with-page-id nil (worker-state/get-context))
                (.releaseAccessHandles worker-obj repo))]
      (<? (p->c work))
 

+ 2 - 2
src/main/frontend/worker/rtc/op_mem_layer.cljs

@@ -4,7 +4,7 @@
   (:require [clojure.core.async :as async :refer [<! go-loop timeout]]
             [clojure.set :as set]
             [frontend.worker.rtc.op-idb-layer :as op-idb-layer]
-            [frontend.worker.state :as state]
+            [frontend.worker.state :as worker-state]
             [malli.core :as m]
             [malli.transform :as mt]
             [promesa.core :as p]
@@ -533,7 +533,7 @@
   []
   (go-loop []
     (<! (timeout 3000))
-    (when-let [repo (state/get-current-repo)]
+    (when-let [repo (worker-state/get-current-repo)]
       (when (and (sqlite-util/db-based-graph? repo)
                  (contains? (@*ops-store repo) :current-branch))
         (<! (<sync-to-idb-layer! repo))))

+ 2 - 2
src/main/frontend/worker/rtc/ws.cljs

@@ -6,7 +6,7 @@
             [cljs.core.async :as async :refer [<! chan offer!]]
             [frontend.worker.async-util :include-macros true :refer [<? go-try]]
             [frontend.worker.rtc.const :as rtc-const]
-            [frontend.worker.state :as state]
+            [frontend.worker.state :as worker-state]
             [goog.string :as gstring]))
 
 (def WebSocketOPEN (if (= *target* "nodejs")
@@ -15,7 +15,7 @@
 
 (defn ws-listen
   [token data-from-ws-chan ws-opened-ch]
-  (let [ws (js/WebSocket. (gstring/format @state/*rtc-ws-url token))]
+  (let [ws (js/WebSocket. (gstring/format @worker-state/*rtc-ws-url token))]
     (set! (.-onopen ws) (fn [_e] (async/close! ws-opened-ch)))
     (set! (.-onmessage ws) (fn [e]
                              (let [data (js->clj (js/JSON.parse (.-data e)) :keywordize-keys true)]

+ 5 - 5
src/main/frontend/worker/search.cljs

@@ -7,7 +7,7 @@
             [goog.object :as gobj]
             [datascript.core :as d]
             [frontend.search.fuzzy :as fuzzy]
-            [frontend.worker.util :as util]
+            [frontend.worker.util :as worker-util]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.common.util :as common-util]))
 
@@ -174,7 +174,7 @@
 (defn- sanitize
   [content]
   (some-> content
-          (util/search-normalize true)))
+          (worker-util/search-normalize true)))
 
 (defn- property-value-when-closed
   "Returns property value if the given entity is type 'closed value' or nil"
@@ -410,14 +410,14 @@
           (if (seq coll')
             (rest coll')
             (reduced false))))
-      (seq (util/search-normalize match true))
-      (seq (util/search-normalize q true))))))
+      (seq (worker-util/search-normalize match true))
+      (seq (worker-util/search-normalize q true))))))
 
 (defn page-search
   "Return a list of page names that match the query"
   [repo db q limit]
   (when repo
-    (let [q (util/search-normalize q true)
+    (let [q (worker-util/search-normalize q true)
           q (fuzzy/clean-str q)
           q (if (= \# (first q)) (subs q 1) q)]
       (when-not (string/blank? q)

+ 3 - 3
src/test/frontend/modules/outliner/pipeline_test.cljs → src/test/frontend/worker/pipeline_test.cljs

@@ -1,8 +1,8 @@
-(ns frontend.modules.outliner.pipeline-test
+(ns frontend.worker.pipeline-test
   (:require [cljs.test :refer [deftest is use-fixtures testing]]
             [datascript.core :as d]
             [frontend.db :as db]
-            [frontend.worker.pipeline :as pipeline]
+            [frontend.worker.pipeline :as worker-pipeline]
             [frontend.test.helper :as test-helper :refer [load-test-files]]))
 
 (use-fixtures :each test-helper/start-and-destroy-db)
@@ -32,7 +32,7 @@
                                          :block/path-refs [{:db/id new-tag-id}])
                                   %)
                                blocks)
-          refs-tx (pipeline/compute-block-path-refs-tx {:tx-meta {:outliner-op :save-block} :db-after @conn} modified-blocks)
+          refs-tx (worker-pipeline/compute-block-path-refs-tx {:tx-meta {:outliner-op :save-block} :db-after @conn} modified-blocks)
           _ (d/transact! conn refs-tx)
           updated-blocks (->> (get-blocks @conn)
                               (map #(hash-map :block/content (:block/content %)