Browse Source

fix: multiple fixes related to lookup-by-name

- only use it for user properties
- don't use create ident fn to lookup names
- fixed get-area-block-asset-url which didn't work for db graphs without
  the frontend
Gabriel Horner 1 year ago
parent
commit
24c48e7a87

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

@@ -144,6 +144,7 @@
              logseq.db.frontend.property.build db-property-build
              logseq.db.frontend.property.type db-property-type
              logseq.db.frontend.property.util db-property-util
+             logseq.db.frontend.entity-plus entity-plus
              logseq.db.frontend.rules rules
              logseq.db.frontend.schema db-schema
              logseq.db.frontend.validate db-validate

+ 16 - 12
deps/publishing/src/logseq/publishing/db.cljs

@@ -3,22 +3,25 @@
   (:require [datascript.core :as d]
             [logseq.db.frontend.rules :as rules]
             [clojure.set :as set]
-            [clojure.string :as string]))
+            [clojure.string :as string]
+            [logseq.db.frontend.entity-plus :as entity-plus]))
 
 (defn ^:api get-area-block-asset-url
   "Returns asset url for an area block used by pdf assets. This lives in this ns
   because it is used by this dep and needs to be independent from the frontend app"
-  ([block page] (get-area-block-asset-url block page {}))
-  ;; TODO: Add prop-lookup-fn support for db graphs and commandline publishing
-  ([block page {:keys [prop-lookup-fn] :or {prop-lookup-fn get}}]
-   (when-some [props (and block page (:block/properties block))]
-     (when-some [uuid (:block/uuid block)]
-       (when-some [stamp (prop-lookup-fn props :hl-stamp)]
-         (let [group-key      (string/replace-first (:block/original-name page) #"^hls__" "")
-               hl-page        (prop-lookup-fn props :hl-page)
-               encoded-chars? (boolean (re-find #"(?i)%[0-9a-f]{2}" group-key))
-               group-key      (if encoded-chars? (js/encodeURI group-key) group-key)]
-           (str "./assets/" group-key "/" (str hl-page "_" uuid "_" stamp ".png"))))))))
+  [db block page]
+  (when-some [props (and block page (:block/properties block))]
+    ;; Can't use db-property-util/lookup b/c repo isn't available
+    (let [prop-lookup-fn (if (entity-plus/db-based-graph? db)
+                           #(get %1 %2)
+                           #(get %1 (keyword (name %2))))]
+      (when-some [uuid (:block/uuid block)]
+        (when-some [stamp (prop-lookup-fn props :logseq.property/hl-stamp)]
+          (let [group-key      (string/replace-first (:block/original-name page) #"^hls__" "")
+                hl-page        (prop-lookup-fn props :logseq.property/hl-page)
+                encoded-chars? (boolean (re-find #"(?i)%[0-9a-f]{2}" group-key))
+                group-key      (if encoded-chars? (js/encodeURI group-key) group-key)]
+            (str "./assets/" group-key "/" (str hl-page "_" uuid "_" stamp ".png"))))))))
 
 (defn- clean-asset-path-prefix
   [path]
@@ -130,6 +133,7 @@
            (= (keyword (get (:v datom) :hl-type)) :area))
           (#(let [path (some-> (pull (:e datom) db)
                                (get-area-block-asset-url
+                                db
                                 (get-page-by-eid (:e datom))))
                   path (clean-asset-path-prefix path)]
               (conj % path)))))

+ 1 - 1
src/main/frontend/components/query_table.cljs

@@ -74,7 +74,7 @@
         properties (:block/properties current-block)
         query-sort-by (pu/lookup properties :logseq.property/query-sort-by)
         ;; Starting with #6105, we started putting properties under namespaces.
-        nlp-date? (and (not db-graph?) (pu/lookup-by-name properties :logseq.query/nlp-date))
+        nlp-date? (and (not db-graph?) (:logseq.query/nlp-date properties))
         sort-by-column (or (if (uuid? query-sort-by) query-sort-by (keyword query-sort-by))
                            (if (query-dsl/query-contains-filter? (:block/content current-block) "sort-by")
                              nil

+ 6 - 3
src/main/frontend/extensions/pdf/assets.cljs

@@ -2,6 +2,7 @@
   (:require [cljs.reader :as reader]
             [clojure.string :as string]
             [frontend.config :as config]
+            [frontend.db.conn :as conn]
             [frontend.db.model :as db-model]
             [frontend.db.utils :as db-utils]
             [frontend.fs :as fs]
@@ -16,7 +17,7 @@
             [frontend.extensions.lightbox :as lightbox]
             [frontend.state :as state]
             [frontend.util :as util]
-            [frontend.extensions.pdf.utils :as pdf-utils]
+            [logseq.publishing.db :as publish-db]
             [frontend.extensions.pdf.windows :as pdf-windows]
             [logseq.common.path :as path]
             [logseq.common.config :as common-config]
@@ -286,8 +287,10 @@
 
 (rum/defc area-display
   [block]
-  (when-let [asset-path' (and block (pdf-utils/get-area-block-asset-url
-                                     block (db-utils/pull (:db/id (:block/page block)))))]
+  (when-let [asset-path' (and block (publish-db/get-area-block-asset-url
+                                     (conn/get-db (state/get-current-repo))
+                                     block
+                                     (db-utils/pull (:db/id (:block/page block)))))]
     (let [asset-path (assets-handler/make-asset-url asset-path')]
       [:span.hl-area
        [:span.actions

+ 1 - 6
src/main/frontend/extensions/pdf/utils.cljs

@@ -4,9 +4,7 @@
             [frontend.util :as util]
             ["/frontend/extensions/pdf/utils" :as js-utils]
             [datascript.core :as d]
-            [logseq.publishing.db :as publish-db]
-            [clojure.string :as string]
-            [frontend.handler.property.util :as pu]))
+            [clojure.string :as string]))
 
 (defonce MAX-SCALE 5.0)
 (defonce MIN-SCALE 0.25)
@@ -16,9 +14,6 @@
   [filename]
   (and filename (string? filename) (string/starts-with? filename "hls__")))
 
-(def get-area-block-asset-url
-  #(publish-db/get-area-block-asset-url %1 %2 {:prop-lookup-fn pu/lookup-by-name}))
-
 (defn get-bounding-rect
   [rects]
   (bean/->clj (js-utils/getBoundingRect (bean/->js rects))))

+ 2 - 6
src/main/frontend/handler/property/util.cljs

@@ -4,7 +4,6 @@
   compatible with file graphs"
   (:require [frontend.state :as state]
             [frontend.db :as db]
-            [datascript.core :as d]
             [logseq.db.sqlite.util :as sqlite-util]
             [logseq.db.frontend.property :as db-property]
             [logseq.db.frontend.property.util :as db-property-util]))
@@ -20,12 +19,9 @@
    for file graphs or for db graphs when user properties are involved"
   [coll key]
   (let [repo (state/get-current-repo)
-        db (db/get-db repo)
-        property-name (if (keyword? key)
-                        (name key)
-                        key)]
+        property-name (if (keyword? key) (name key) key)]
     (if (sqlite-util/db-based-graph? repo)
-      (when-let [property (d/entity db (db-property/create-user-property-ident-from-name property-name))]
+      (when-let [property (db/get-case-page property-name)]
         (get coll (:block/uuid property)))
       (get coll key))))