mirror of
https://github.com/logseq/logseq.git
synced 2026-05-28 14:39:48 +00:00
fix: model lint and remove unused fns and frontend.db
bindings
This commit is contained in:
committed by
Tienson Qin
parent
b985020d1f
commit
5be0d024ae
@@ -3,7 +3,6 @@
|
||||
(:require [frontend.config :as config]
|
||||
[frontend.db.conn :as conn]
|
||||
[frontend.db.model]
|
||||
[frontend.db.react :as react]
|
||||
[frontend.db.utils]
|
||||
[frontend.modules.outliner.op :as outliner-op]
|
||||
[frontend.modules.outliner.ui :as ui-outliner-tx]
|
||||
@@ -26,20 +25,14 @@
|
||||
|
||||
[frontend.db.model
|
||||
delete-files get-block-and-children get-block-by-uuid get-block-children sort-by-order
|
||||
get-block-parent get-block-parents parents-collapsed? get-block-referenced-blocks
|
||||
get-block-parent get-block-parents parents-collapsed?
|
||||
get-block-immediate-children get-block-page
|
||||
get-custom-css get-file file-exists? get-files-full get-journals-length
|
||||
get-file file-exists? get-files-full
|
||||
get-latest-journals get-page get-case-page get-page-alias-names
|
||||
get-page-blocks-count get-page-blocks-no-cache get-page-format
|
||||
get-referenced-blocks journal-page? page? page-alias-set sub-block sub-entity
|
||||
get-page-blocks-no-cache get-page-format
|
||||
journal-page? page? sub-block
|
||||
page-empty? page-exists? get-alias-source-page
|
||||
has-children? whiteboard-page?]
|
||||
|
||||
[frontend.db.react
|
||||
get-current-page
|
||||
remove-query-component! add-q! add-query-component! clear-query-state!
|
||||
q
|
||||
query-state component->query-key set-new-result!])
|
||||
has-children? whiteboard-page?])
|
||||
|
||||
(defn start-db-conn!
|
||||
([repo]
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
(ns frontend.db.model
|
||||
"Core db functions."
|
||||
;; TODO: Remove this config once how repos are passed to this ns are standardized
|
||||
{:clj-kondo/config {:linters {:unused-binding {:level :off}}}}
|
||||
(:require [clojure.set :as set]
|
||||
[clojure.string :as string]
|
||||
[clojure.walk :as walk]
|
||||
@@ -16,12 +14,10 @@
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util :refer [react]]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.common.util.date-time :as date-time-util]
|
||||
[logseq.db :as ldb]
|
||||
[logseq.db.frontend.class :as db-class]
|
||||
[logseq.db.frontend.content :as db-content]
|
||||
[logseq.db.frontend.rules :as rules]
|
||||
[logseq.shui.hooks :as hooks]))
|
||||
[logseq.db.frontend.rules :as rules]))
|
||||
|
||||
;; TODO: extract to specific models and move data transform logic to the
|
||||
;; corresponding handlers.
|
||||
@@ -149,8 +145,7 @@ independent of format as format specific heading characters are stripped"
|
||||
|
||||
(defn get-page-alias-names
|
||||
[repo page-id]
|
||||
(let [page (db-utils/entity page-id)
|
||||
alias-ids (->> (page-alias-set repo page-id)
|
||||
(let [alias-ids (->> (page-alias-set repo page-id)
|
||||
(remove #{page-id}))]
|
||||
(when (seq alias-ids)
|
||||
(map (fn [id] (:block/title (db-utils/entity id))) alias-ids))))
|
||||
@@ -186,21 +181,6 @@ independent of format as format specific heading characters are stripped"
|
||||
(when-let [id (:db/id e)]
|
||||
(db-utils/entity id))))))))
|
||||
|
||||
(defn sub-entity
|
||||
"Used for react function components"
|
||||
[entity* watch-id]
|
||||
(let [id (:db/id entity*)
|
||||
*ref (sub-block id {:ref? true})
|
||||
[entity set-entity!] (hooks/use-state @*ref)]
|
||||
(add-watch *ref watch-id (fn [_ _ _ new-value]
|
||||
(set-entity! new-value)))
|
||||
(hooks/use-effect!
|
||||
(fn []
|
||||
#(remove-watch *ref watch-id))
|
||||
[])
|
||||
|
||||
[entity set-entity!]))
|
||||
|
||||
(defn sort-by-order-recursive
|
||||
[form]
|
||||
(walk/postwalk (fn [f]
|
||||
@@ -394,27 +374,6 @@ independent of format as format specific heading characters are stripped"
|
||||
(:block/name page-entity)
|
||||
page-name)))))))
|
||||
|
||||
(defn get-journals-length
|
||||
[]
|
||||
(let [today (date-time-util/date->int (js/Date.))]
|
||||
(if (config/db-based-graph?)
|
||||
(d/q '[:find (count ?page) .
|
||||
:in $ ?today
|
||||
:where
|
||||
[?page :block/tags :logseq.class/Journal]
|
||||
[?page :block/journal-day ?journal-day]
|
||||
[(<= ?journal-day ?today)]]
|
||||
(conn/get-db (state/get-current-repo))
|
||||
today)
|
||||
(d/q '[:find (count ?page) .
|
||||
:in $ ?today
|
||||
:where
|
||||
[?page :block/type "journal"]
|
||||
[?page :block/journal-day ?journal-day]
|
||||
[(<= ?journal-day ?today)]]
|
||||
(conn/get-db (state/get-current-repo))
|
||||
today))))
|
||||
|
||||
(defn get-latest-journals
|
||||
([n]
|
||||
(get-latest-journals (state/get-current-repo) n))
|
||||
@@ -430,10 +389,8 @@ independent of format as format specific heading characters are stripped"
|
||||
|
||||
(defn get-page-referenced-blocks-full
|
||||
([page-id]
|
||||
(get-page-referenced-blocks-full (state/get-current-repo) page-id nil))
|
||||
([page-id options]
|
||||
(get-page-referenced-blocks-full (state/get-current-repo) page-id options))
|
||||
([repo page-id options]
|
||||
(get-page-referenced-blocks-full (state/get-current-repo) page-id))
|
||||
([repo page-id]
|
||||
(when (and repo page-id)
|
||||
(when-let [db (conn/get-db repo)]
|
||||
(let [pages (page-alias-set repo page-id)
|
||||
@@ -457,10 +414,8 @@ independent of format as format specific heading characters are stripped"
|
||||
|
||||
(defn get-referenced-blocks
|
||||
([eid]
|
||||
(get-referenced-blocks (state/get-current-repo) eid nil))
|
||||
([eid options]
|
||||
(get-referenced-blocks (state/get-current-repo) eid options))
|
||||
([repo eid options]
|
||||
(get-referenced-blocks (state/get-current-repo) eid))
|
||||
([repo eid]
|
||||
(when repo
|
||||
(when (conn/get-db repo)
|
||||
(let [entity (db-utils/entity eid)
|
||||
@@ -478,14 +433,12 @@ independent of format as format specific heading characters are stripped"
|
||||
(util/distinct-by :db/id)))))))
|
||||
|
||||
(defn get-block-referenced-blocks
|
||||
([block-id]
|
||||
(get-block-referenced-blocks block-id {}))
|
||||
([block-id options]
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
(when (conn/get-db repo)
|
||||
(->> (get-referenced-blocks repo block-id options)
|
||||
(sort-by-order-recursive)
|
||||
db-utils/group-by-page)))))
|
||||
[block-id]
|
||||
(when-let [repo (state/get-current-repo)]
|
||||
(when (conn/get-db repo)
|
||||
(->> (get-referenced-blocks repo block-id)
|
||||
(sort-by-order-recursive)
|
||||
db-utils/group-by-page))))
|
||||
|
||||
(defn journal-page?
|
||||
"sanitized page-name only"
|
||||
|
||||
@@ -6,14 +6,11 @@
|
||||
"
|
||||
(:require [clojure.core.async :as async]
|
||||
[datascript.core :as d]
|
||||
[frontend.date :as date]
|
||||
[frontend.db.async.util :as db-async-util]
|
||||
[frontend.db.conn :as conn]
|
||||
[frontend.db.utils :as db-utils]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
[logseq.common.util :as common-util]
|
||||
[logseq.db :as ldb]
|
||||
[promesa.core :as p]))
|
||||
|
||||
;; Query atom of map of Key ([repo q inputs]) -> atom
|
||||
@@ -151,19 +148,6 @@
|
||||
(set! (.-state result-atom) result')
|
||||
result-atom))))))))
|
||||
|
||||
(defn get-current-page
|
||||
[]
|
||||
(let [match (:route-match @state/state)
|
||||
route-name (get-in match [:data :name])
|
||||
page (case route-name
|
||||
:page
|
||||
(get-in match [:path-params :name])
|
||||
(date/journal-name))]
|
||||
(when page
|
||||
(if (common-util/uuid-string? page)
|
||||
(db-utils/entity [:block/uuid (uuid page)])
|
||||
(ldb/get-page (conn/get-db) page)))))
|
||||
|
||||
(defn- execute-query!
|
||||
[graph db k {:keys [query inputs transform-fn query-fn inputs-fn result built-in-query?]
|
||||
:or {transform-fn identity}}]
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
[frontend.date :as date]
|
||||
[frontend.db :as db]
|
||||
[frontend.db.persist :as db-persist]
|
||||
[frontend.db.react :as react]
|
||||
[frontend.db.restore :as db-restore]
|
||||
[frontend.handler.common.config-edn :as config-edn-common-handler]
|
||||
[frontend.handler.global-config :as global-config-handler]
|
||||
@@ -86,7 +87,7 @@
|
||||
(when url
|
||||
(search/reset-indice! url)
|
||||
(db/remove-conn! url)
|
||||
(db/clear-query-state!)
|
||||
(react/clear-query-state!)
|
||||
(-> (p/do! (db-persist/delete-graph! url))
|
||||
(p/catch (fn [error]
|
||||
(prn "Delete repo failed, error: " error)))))))
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[frontend.state :as state]
|
||||
[frontend.components.file-based.query-table :as query-table]
|
||||
[frontend.db.query-dsl :as query-dsl]
|
||||
[frontend.db :as db]
|
||||
[frontend.db.react :as react]
|
||||
[frontend.util :as util]))
|
||||
|
||||
(use-fixtures :each {:before test-helper/start-test-db!
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
(defn- dsl-query
|
||||
[s]
|
||||
(db/clear-query-state!)
|
||||
(react/clear-query-state!)
|
||||
(when-let [result (query-dsl/query test-helper/test-db s)]
|
||||
(map first (deref result))))
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[clojure.string :as string]
|
||||
[frontend.db :as db]
|
||||
[frontend.db.query-dsl :as query-dsl]
|
||||
[frontend.db.react :as react]
|
||||
[frontend.test.helper :as test-helper :include-macros true :refer [load-test-files load-test-files-for-db-graph]]
|
||||
[frontend.util :as util]
|
||||
[logseq.common.util.page-ref :as page-ref]))
|
||||
@@ -72,13 +73,13 @@
|
||||
|
||||
(defn- dsl-query
|
||||
[s]
|
||||
(db/clear-query-state!)
|
||||
(react/clear-query-state!)
|
||||
(when-let [result (dsl-query* test-helper/test-db (->smart-query s))]
|
||||
(map first (deref result))))
|
||||
|
||||
(defn- custom-query
|
||||
[query]
|
||||
(db/clear-query-state!)
|
||||
(react/clear-query-state!)
|
||||
(when-let [result (with-redefs [query-dsl/db-block-attrs db-block-attrs]
|
||||
(query-dsl/custom-query test-helper/test-db query {}))]
|
||||
(map first (deref result))))
|
||||
|
||||
Reference in New Issue
Block a user