Browse Source

chore: DRY up duplicated vars and needless/confusing aliases

Gabriel Horner 1 year ago
parent
commit
2305d09cc8

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

@@ -1,5 +1,5 @@
 (ns logseq.common.config
 (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]
   (:require [clojure.string :as string]
             [goog.object :as gobj]))
             [goog.object :as gobj]))
 
 
@@ -25,9 +25,7 @@
                 (hidden? path patterns))) files)
                 (hidden? path patterns))) files)
     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 asset-protocol "assets://")
 (defonce capacitor-protocol "capacitor://")
 (defonce capacitor-protocol "capacitor://")

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

@@ -1,5 +1,5 @@
 (ns logseq.db.frontend.content
 (ns logseq.db.frontend.content
-  "fns to handle special ids"
+  "Fns to handle block content e.g. special ids"
   (:require [clojure.string :as string]
   (:require [clojure.string :as string]
             [logseq.common.util.page-ref :as page-ref]
             [logseq.common.util.page-ref :as page-ref]
             [datascript.core :as d]
             [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
 (ns logseq.db.frontend.property.util
   "Util fns for building core property concepts"
   "Util fns for building core property concepts"
   (:require [logseq.db.sqlite.util :as sqlite-util]
   (:require [logseq.db.sqlite.util :as sqlite-util]
+            [logseq.common.util :as common-util]
             [datascript.core :as d]))
             [datascript.core :as d]))
 
 
 (defonce hidden-page-name-prefix "$$$")
 (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"
   "Builds a basic page to be transacted. A minimal version of gp-block/page-name->map"
   [page-name]
   [page-name]
   (sqlite-util/block-with-timestamps
   (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/original-name page-name
     :block/journal? false
     :block/journal? false
     :block/uuid (d/squuid)}))
     :block/uuid (d/squuid)}))
@@ -54,7 +55,7 @@
   {:block/uuid prop-uuid
   {:block/uuid prop-uuid
    :block/schema (merge {:type :default} prop-schema)
    :block/schema (merge {:type :default} prop-schema)
    :block/original-name (name prop-name)
    :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
 (defn build-closed-values
   "Builds all the tx needed for property with closed values including
   "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.schema :as db-schema]
             [logseq.db.frontend.property :as db-property]
             [logseq.db.frontend.property :as db-property]
             [logseq.db.frontend.property.util :as db-property-util]
             [logseq.db.frontend.property.util :as db-property-util]
+            [logseq.common.util :as common-util]
             [datascript.core :as d]
             [datascript.core :as d]
             [logseq.db :as ldb]))
             [logseq.db :as ldb]))
 
 
@@ -35,7 +36,7 @@
                                   [(sqlite-util/build-new-property
                                   [(sqlite-util/build-new-property
                                     {:block/schema schema
                                     {:block/schema schema
                                      :block/original-name (or original-name k-name)
                                      :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)})])))
                                      :block/uuid (d/squuid)})])))
                             db-property/built-in-properties)
                             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))]
                 (assoc :block/created-at updated-at))]
     block))
     block))
 
 
-(def sanitize-page-name common-util/page-name-sanity-lc)
-
 (defn build-new-property
 (defn build-new-property
   "Build a standard new property so that it is is consistent across contexts"
   "Build a standard new property so that it is is consistent across contexts"
   [block]
   [block]

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

@@ -33,17 +33,6 @@
     db
     db
     file-path)))
     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
 (defn get-blocks-to-delete
   "Returns the transactional operations to retract blocks belonging to the
   "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
   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)
   (let [existing-file-page (get-file-page db file-path)
         pages-to-clear (distinct (filter some? [existing-file-page (:block/name file-page)]))
         pages-to-clear (distinct (filter some? [existing-file-page (:block/name file-page)]))
         blocks (mapcat (fn [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)
                        pages-to-clear)
         retain-uuids (set (keep :block/uuid retain-uuid-blocks))]
         retain-uuids (set (keep :block/uuid retain-uuid-blocks))]
     (retract-blocks-tx (distinct blocks) retain-uuids)))
     (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.sqlite.create-graph :as sqlite-create-graph]
             [logseq.db.frontend.property.util :as db-property-util]
             [logseq.db.frontend.property.util :as db-property-util]
             [logseq.outliner.cli.pipeline :as cli-pipeline]
             [logseq.outliner.cli.pipeline :as cli-pipeline]
+            [logseq.common.util :as common-util]
             [logseq.db :as ldb]
             [logseq.db :as ldb]
             [clojure.string :as string]
             [clojure.string :as string]
             [datascript.core :as d]
             [datascript.core :as d]
@@ -83,7 +84,7 @@
                             (into {}))
                             (into {}))
         page-uuids (->> pages-and-blocks
         page-uuids (->> pages-and-blocks
                         (map :page)
                         (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))
                                    :block/uuid))
                         (into {}))
                         (into {}))
         block-uuids (->> pages-and-blocks
         block-uuids (->> pages-and-blocks
@@ -194,7 +195,7 @@
                  (merge
                  (merge
                   {:db/id page-id
                   {:db/id page-id
                    :block/original-name (or (:block/original-name page) (string/capitalize (:block/name page)))
                    :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/journal? false
                    :block/format :markdown}
                    :block/format :markdown}
                   (dissoc page :properties)
                   (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
    Also creates a page of queries that exercises most properties
    NOTE: This script is also used in CI to confirm graph creation works"
    NOTE: This script is also used in CI to confirm graph creation works"
   (:require [logseq.tasks.db-graph.create-graph :as create-graph]
   (: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]
             [logseq.db.frontend.property.type :as db-property-type]
             [clojure.string :as string]
             [clojure.string :as string]
             [datascript.core :as d]
             [datascript.core :as d]
@@ -14,7 +14,7 @@
 (defn- date-journal-title [date]
 (defn- date-journal-title [date]
   (let [title (.toLocaleString date "en-US" #js {:month "short" :day "numeric" :year "numeric"})
   (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"}]
         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"))))))
      (string/replace-first title #"(\d+)" (str "$1" (suffixes (.getDate date) "th"))))))
 
 
 (defn- date-journal-day [date]
 (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
        type logseq doesnt' support yet
      * schema.org assumes no cardinality. For now, only :page properties are given a :cardinality :many"
      * 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]
   (: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]
             [clojure.string :as string]
             [datascript.core :as d]
             [datascript.core :as d]
             ["path" :as node-path]
             ["path" :as node-path]
@@ -170,7 +170,7 @@
   [property-ids class-ids {:keys [verbose]}]
   [property-ids class-ids {:keys [verbose]}]
   (let [conflicts
   (let [conflicts
         (->> (concat property-ids class-ids)
         (->> (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))
              (filter #(> (count (val %)) 1))
              vals)
              vals)
         ;; If this assertion fails then renamed-classes approach to resolving
         ;; 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
 (def website
   (if dev?
   (if dev?
     "http://localhost:3000"
     "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
   get-all-pages get-pages-relation get-pages-that-mentioned-page get-tag-pages
   journal-page? page-alias-set sub-block
   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-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
  [frontend.db.react
   get-current-page set-key-value
   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 :as util :refer [react]]
             [frontend.util.drawer :as drawer]
             [frontend.util.drawer :as drawer]
             [logseq.db.frontend.rules :as rules]
             [logseq.db.frontend.rules :as rules]
+            [logseq.db.frontend.content :as db-content]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.text :as text]
             [logseq.graph-parser.util.db :as db-util]
             [logseq.graph-parser.util.db :as db-util]
             [logseq.common.util :as common-util]
             [logseq.common.util :as common-util]
@@ -27,8 +28,6 @@
 
 
 (def block-attrs ldb/block-attrs)
 (def block-attrs ldb/block-attrs)
 
 
-(def get-original-name util/get-page-original-name)
-
 (defn get-tag-pages
 (defn get-tag-pages
   [repo tag-name]
   [repo tag-name]
   (when 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)
                   (let [block (db-utils/entity repo block-id)
                         ref-tags (distinct (concat (:block/tags block) (:block/refs block)))]
                         ref-tags (distinct (concat (:block/tags block) (:block/refs block)))]
                     (= (-> block-content
                     (= (-> 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)
                            heading-content->route-name)
                        (string/lower-case external-content)))))
                        (string/lower-case external-content)))))
            ffirst)
            ffirst)

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

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

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

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