瀏覽代碼

chore: DRY up duplicated vars and needless/confusing aliases

Gabriel Horner 1 年之前
父節點
當前提交
2305d09cc8

+ 2 - 4
deps/common/src/logseq/common/config.cljs

@@ -1,5 +1,5 @@
 (ns logseq.common.config
-  "App config that is shared between the app"
+  "Common config that is shared between deps and app"
   (:require [clojure.string :as string]
             [goog.object :as gobj]))
 
@@ -25,9 +25,7 @@
                 (hidden? path patterns))) files)
     files))
 
-(def app-name
-  "Copy of frontend.config/app-name. Too small to couple to main app"
-  "logseq")
+(def app-name "logseq")
 
 (defonce asset-protocol "assets://")
 (defonce capacitor-protocol "capacitor://")

+ 1 - 1
deps/db/src/logseq/db/frontend/content.cljs

@@ -1,5 +1,5 @@
 (ns logseq.db.frontend.content
-  "fns to handle special ids"
+  "Fns to handle block content e.g. special ids"
   (:require [clojure.string :as string]
             [logseq.common.util.page-ref :as page-ref]
             [datascript.core :as d]

+ 3 - 2
deps/db/src/logseq/db/frontend/property/util.cljs

@@ -1,6 +1,7 @@
 (ns logseq.db.frontend.property.util
   "Util fns for building core property concepts"
   (:require [logseq.db.sqlite.util :as sqlite-util]
+            [logseq.common.util :as common-util]
             [datascript.core :as d]))
 
 (defonce hidden-page-name-prefix "$$$")
@@ -33,7 +34,7 @@
   "Builds a basic page to be transacted. A minimal version of gp-block/page-name->map"
   [page-name]
   (sqlite-util/block-with-timestamps
-   {:block/name (sqlite-util/sanitize-page-name page-name)
+   {:block/name (common-util/page-name-sanity-lc page-name)
     :block/original-name page-name
     :block/journal? false
     :block/uuid (d/squuid)}))
@@ -54,7 +55,7 @@
   {:block/uuid prop-uuid
    :block/schema (merge {:type :default} prop-schema)
    :block/original-name (name prop-name)
-   :block/name (sqlite-util/sanitize-page-name (name prop-name))})
+   :block/name (common-util/page-name-sanity-lc (name prop-name))})
 
 (defn build-closed-values
   "Builds all the tx needed for property with closed values including

+ 2 - 1
deps/db/src/logseq/db/sqlite/create_graph.cljs

@@ -4,6 +4,7 @@
             [logseq.db.frontend.schema :as db-schema]
             [logseq.db.frontend.property :as db-property]
             [logseq.db.frontend.property.util :as db-property-util]
+            [logseq.common.util :as common-util]
             [datascript.core :as d]
             [logseq.db :as ldb]))
 
@@ -35,7 +36,7 @@
                                   [(sqlite-util/build-new-property
                                     {:block/schema schema
                                      :block/original-name (or original-name k-name)
-                                     :block/name (sqlite-util/sanitize-page-name k-name)
+                                     :block/name (common-util/page-name-sanity-lc k-name)
                                      :block/uuid (d/squuid)})])))
                             db-property/built-in-properties)
         ]

+ 0 - 2
deps/db/src/logseq/db/sqlite/util.cljs

@@ -33,8 +33,6 @@
                 (assoc :block/created-at updated-at))]
     block))
 
-(def sanitize-page-name common-util/page-name-sanity-lc)
-
 (defn build-new-property
   "Build a standard new property so that it is is consistent across contexts"
   [block]

+ 1 - 12
deps/graph-parser/src/logseq/graph_parser.cljs

@@ -33,17 +33,6 @@
     db
     file-path)))
 
-(defn- get-page-blocks-no-cache
-  "Copy of db/get-page-blocks-no-cache. Too basic to couple to main app"
-  [db page {:keys [pull-keys]
-            :or {pull-keys '[*]}}]
-  (let [sanitized-page (common-util/page-name-sanity-lc page)
-        page-id (:db/id (d/entity db [:block/name sanitized-page]))]
-    (when page-id
-      (let [datoms (d/datoms db :avet :block/page page-id)
-            block-eids (mapv :e datoms)]
-        (d/pull-many db pull-keys block-eids)))))
-
 (defn get-blocks-to-delete
   "Returns the transactional operations to retract blocks belonging to the
   given page name and file path. This function is required when a file is being
@@ -64,7 +53,7 @@
   (let [existing-file-page (get-file-page db file-path)
         pages-to-clear (distinct (filter some? [existing-file-page (:block/name file-page)]))
         blocks (mapcat (fn [page]
-                         (get-page-blocks-no-cache db page {:pull-keys [:db/id :block/uuid]}))
+                         (ldb/get-page-blocks db page {:pull-keys [:db/id :block/uuid]}))
                        pages-to-clear)
         retain-uuids (set (keep :block/uuid retain-uuid-blocks))]
     (retract-blocks-tx (distinct blocks) retain-uuids)))

+ 3 - 2
scripts/src/logseq/tasks/db_graph/create_graph.cljs

@@ -8,6 +8,7 @@
             [logseq.db.sqlite.create-graph :as sqlite-create-graph]
             [logseq.db.frontend.property.util :as db-property-util]
             [logseq.outliner.cli.pipeline :as cli-pipeline]
+            [logseq.common.util :as common-util]
             [logseq.db :as ldb]
             [clojure.string :as string]
             [datascript.core :as d]
@@ -83,7 +84,7 @@
                             (into {}))
         page-uuids (->> pages-and-blocks
                         (map :page)
-                        (map (juxt #(or (:block/name %) (sqlite-util/sanitize-page-name (:block/original-name %)))
+                        (map (juxt #(or (:block/name %) (common-util/page-name-sanity-lc (:block/original-name %)))
                                    :block/uuid))
                         (into {}))
         block-uuids (->> pages-and-blocks
@@ -194,7 +195,7 @@
                  (merge
                   {:db/id page-id
                    :block/original-name (or (:block/original-name page) (string/capitalize (:block/name page)))
-                   :block/name (or (:block/name page) (sqlite-util/sanitize-page-name (:block/original-name page)))
+                   :block/name (or (:block/name page) (common-util/page-name-sanity-lc (:block/original-name page)))
                    :block/journal? false
                    :block/format :markdown}
                   (dissoc page :properties)

+ 2 - 2
scripts/src/logseq/tasks/db_graph/create_graph_with_properties.cljs

@@ -3,7 +3,7 @@
    Also creates a page of queries that exercises most properties
    NOTE: This script is also used in CI to confirm graph creation works"
   (:require [logseq.tasks.db-graph.create-graph :as create-graph]
-            [logseq.db.sqlite.util :as sqlite-util]
+            [logseq.common.util :as common-util]
             [logseq.db.frontend.property.type :as db-property-type]
             [clojure.string :as string]
             [datascript.core :as d]
@@ -14,7 +14,7 @@
 (defn- date-journal-title [date]
   (let [title (.toLocaleString date "en-US" #js {:month "short" :day "numeric" :year "numeric"})
         suffixes {1 "st" 21 "st" 31 "st" 2 "nd" 22 "nd" 3 "rd" 23 "rd" 33 "rd"}]
-    (sqlite-util/sanitize-page-name
+    (common-util/page-name-sanity-lc
      (string/replace-first title #"(\d+)" (str "$1" (suffixes (.getDate date) "th"))))))
 
 (defn- date-journal-day [date]

+ 2 - 2
scripts/src/logseq/tasks/db_graph/create_graph_with_schema_org.cljs

@@ -11,7 +11,7 @@
        type logseq doesnt' support yet
      * schema.org assumes no cardinality. For now, only :page properties are given a :cardinality :many"
   (:require [logseq.tasks.db-graph.create-graph :as create-graph]
-            [logseq.db.sqlite.util :as sqlite-util]
+            [logseq.common.util :as common-util]
             [clojure.string :as string]
             [datascript.core :as d]
             ["path" :as node-path]
@@ -170,7 +170,7 @@
   [property-ids class-ids {:keys [verbose]}]
   (let [conflicts
         (->> (concat property-ids class-ids)
-             (group-by (comp sqlite-util/sanitize-page-name first))
+             (group-by (comp common-util/page-name-sanity-lc first))
              (filter #(> (count (val %)) 1))
              vals)
         ;; If this assertion fails then renamed-classes approach to resolving

+ 1 - 1
src/main/frontend/config.cljs

@@ -95,7 +95,7 @@
 
 ;; ============
 
-(def app-name "logseq")
+(def app-name common-config/app-name)
 (def website
   (if dev?
     "http://localhost:3000"

+ 1 - 2
src/main/frontend/db.cljs

@@ -43,8 +43,7 @@
   get-all-pages get-pages-relation get-pages-that-mentioned-page get-tag-pages
   journal-page? page-alias-set sub-block
   set-file-last-modified-at! page-empty? page-exists? page-empty-or-dummy? get-alias-source-page
-  set-file-content! has-children? get-namespace-pages get-all-namespace-relation
-  get-original-name]
+  set-file-content! has-children? get-namespace-pages get-all-namespace-relation]
 
  [frontend.db.react
   get-current-page set-key-value

+ 3 - 4
src/main/frontend/db/model.cljs

@@ -14,6 +14,7 @@
             [frontend.util :as util :refer [react]]
             [frontend.util.drawer :as drawer]
             [logseq.db.frontend.rules :as rules]
+            [logseq.db.frontend.content :as db-content]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.util.db :as db-util]
             [logseq.common.util :as common-util]
@@ -27,8 +28,6 @@
 
 (def block-attrs ldb/block-attrs)
 
-(def get-original-name util/get-page-original-name)
-
 (defn get-tag-pages
   [repo tag-name]
   (when tag-name
@@ -234,8 +233,8 @@ independent of format as format specific heading characters are stripped"
                   (let [block (db-utils/entity repo block-id)
                         ref-tags (distinct (concat (:block/tags block) (:block/refs block)))]
                     (= (-> block-content
-                           (db-utils/special-id->page ref-tags)
-                           (db-utils/special-id-ref->page ref-tags)
+                           (db-content/special-id->page ref-tags)
+                           (db-content/special-id-ref->page ref-tags)
                            heading-content->route-name)
                        (string/lower-case external-content)))))
            ffirst)

+ 0 - 4
src/main/frontend/db/utils.cljs

@@ -57,10 +57,6 @@
                    repo-or-db)]
      (d/entity db id-or-lookup-ref))))
 
-(def special-id->page db-content/special-id->page)
-
-(def special-id-ref->page db-content/special-id-ref->page)
-
 (defn update-block-content
   "Replace `[[internal-id]]` with `[[page name]]`"
   [item eid]

+ 2 - 2
src/main/frontend/handler/graph.cljs

@@ -95,7 +95,7 @@
             tags (set (map second tagged-pages))
             full-pages (db/get-all-pages repo)
             full-pages-map (into {} (map (juxt :block/name identity) full-pages))
-            all-pages (map db/get-original-name full-pages)
+            all-pages (map common-util/get-page-original-name full-pages)
             page-name->original-name (zipmap (map :block/name full-pages) all-pages)
             created-ats (map :block/created-at full-pages)
 
@@ -183,7 +183,7 @@
                        (distinct))
             nodes (build-nodes dark? page links (set tags) nodes namespaces)
             full-pages (db/get-all-pages repo)
-            all-pages (map db/get-original-name full-pages)
+            all-pages (map common-util/get-page-original-name full-pages)
             page-name->original-name (zipmap (map :block/name full-pages) all-pages)]
         (normalize-page-name
          {:nodes nodes