Browse Source

wip: replace property uuid/name with db ident

Tienson Qin 1 year ago
parent
commit
849d19f190

+ 4 - 2
src/main/frontend/components/db_based/page.cljs

@@ -70,10 +70,12 @@
       (icon-component/icon-picker icon-value
                                   {:disabled? config/publishing?
                                    :on-chosen (fn [_e icon]
-                                                (db-property-handler/<update-property!
+                                                (db-property-handler/set-block-property!
                                                  (state/get-current-repo)
                                                  (:block/uuid page)
-                                                 {:properties {:logseq.property/icon icon}}))})
+                                                 :logseq.property/icon
+                                                 icon
+                                                 {}))})
       (when (and icon-value (not config/publishing?))
         [:a.fade-link.flex {:on-click (fn [_e]
                                         (db-property-handler/remove-block-property!

+ 4 - 2
src/main/frontend/components/page.cljs

@@ -337,10 +337,12 @@
               (if (and (map? icon) db-based?)
                 (icon-component/icon-picker icon
                                             {:on-chosen (fn [_e icon]
-                                                          (db-property-handler/<update-property!
+                                                          (db-property-handler/set-block-property!
                                                            repo
                                                            (:block/uuid page)
-                                                           {:properties {:logseq.property/icon icon}}))
+                                                           :logseq.property/icon
+                                                           icon
+                                                           {}))
                                              :icon-props {:size 38}})
                 icon)])
            [:h1.page-title.flex-1.cursor-pointer.gap-1

+ 2 - 2
src/main/frontend/components/property.cljs

@@ -249,7 +249,7 @@
                                           {:on-chosen (fn [_e icon]
                                                         (db-property-handler/<update-property!
                                                          (state/get-current-repo)
-                                                         (:block/uuid property)
+                                                         (:db/ident property)
                                                          {:properties {:logseq.property/icon icon}}))})
 
               (when icon-value
@@ -576,7 +576,7 @@
                           (fn [_e icon]
                             (when icon
                               (p/let [_ (db-property-handler/<update-property! repo
-                                                                               (:block/uuid property)
+                                                                               (:db/ident property)
                                                                                {:properties {:logseq.property/icon icon}})]
                                 (shui/popup-hide! id))))}))]
        (shui/trigger-as :button

+ 1 - 1
src/main/frontend/components/property/util.cljs

@@ -7,6 +7,6 @@
   [property property-name property-schema]
   (db-property-handler/<update-property!
    (state/get-current-repo)
-   (:block/uuid property)
+   (:db/ident property)
    {:property-name property-name
     :property-schema property-schema}))

+ 6 - 53
src/main/frontend/db/async.cljs

@@ -3,7 +3,6 @@
   (:require [promesa.core :as p]
             [frontend.state :as state]
             [frontend.config :as config]
-            [clojure.string :as string]
             [frontend.util :as util]
             [frontend.db.utils :as db-utils]
             [frontend.db.async.util :as db-async-util]
@@ -16,9 +15,7 @@
             [frontend.date :as date]
             [cljs-time.core :as t]
             [cljs-time.format :as tf]
-            [logseq.db :as ldb]
-            [frontend.handler.property.util :as pu]
-            [logseq.db.frontend.property :as db-property]))
+            [logseq.db :as ldb]))
 
 (def <q db-async-util/<q)
 (def <pull db-async-util/<pull)
@@ -77,64 +74,20 @@
                          [(get-else $ ?page :block/original-name ?page-name) ?page-original-name]])]
       (remove db-model/hidden-page? result))))
 
-(defn <get-db-based-property-values
-  [graph property]
-  (let [property-name (-> (if (keyword? property) (name property) property)
-                          util/page-name-sanity-lc)
-        property (pu/get-property property-name)
-        closed-values? (seq (get-in property [:block/schema :values]))]
-    (p/let [result (<q graph
-                       '[:find ?prop-type ?v
-                         :in $ ?prop-name
-                         :where
-                         [?b :block/properties ?bp]
-                         [?prop-b :block/name ?prop-name]
-                         [?prop-b :block/uuid ?prop-uuid]
-                         [?prop-b :block/schema ?prop-schema]
-                         [(get ?prop-schema :type) ?prop-type]
-                         [(get ?bp ?prop-uuid) ?v]
-                         [(not= ?v :property/empty-placeholder)]]
-                       property-name)]
-      (->> result
-           (map (fn [[prop-type v]] [prop-type (if (coll? v) v [v])]))
-           (mapcat (fn [[prop-type vals]]
-                     (let [result (if closed-values?
-                                    (map #(db-property/closed-value-name (db-utils/entity graph [:block/uuid %]))
-                                         vals)
-                                    (case prop-type
-                                      :default
-                                      ;; Remove multi-block properties as there isn't a supported approach to query them yet
-                                      (map str (remove uuid? vals))
-                                      (:page :date)
-                                      (map #(:block/original-name (db-utils/entity graph [:block/uuid %]))
-                                           vals)
-                                      :number
-                                      vals
-                                      ;; Checkboxes returned as strings as builder doesn't display boolean values correctly
-                                      (map str vals)))]
-                       result)))
-           ;; Remove blanks as they match on everything
-           (remove string/blank?)
-           (distinct)
-           (sort)))))
-
 (defn <get-property-values
   [graph property]
-  (if (config/db-based-graph? graph)
-    (<get-db-based-property-values graph property)
+  (when-not (config/db-based-graph? graph)
     (file-async/<get-file-based-property-values graph property)))
 
 (defn <get-block-property-values
-  [graph property-uuid]
+  [graph property-id]
   (<q graph
       '[:find ?b ?v
-        :in $ ?property-uuid
+        :in $ ?property-id
         :where
-        [?b :block/properties ?p]
-        [(get ?p ?property-uuid) ?v]
-        [(some? ?v)]
+        [?b ?property-id ?v]
         [(not= ?v :property/empty-placeholder)]]
-      property-uuid))
+      property-id))
 
 ;; TODO: batch queries for better performance and UX
 (defn <get-block

+ 5 - 5
src/main/frontend/handler/db_based/property.cljs

@@ -242,16 +242,16 @@
                     (db/transact! repo [block] {:outliner-op :save-block})))))))))))
 
 (defn <update-property!
-  [repo property-uuid {:keys [property-name property-schema properties]}]
-  {:pre [(uuid? property-uuid)]}
-  (when-let [property (db/entity [:block/uuid property-uuid])]
+  [repo property-id {:keys [property-name property-schema properties]}]
+  (assert (keyword? property-id) (str "property-id " property-id " is not a keyword"))
+  (when-let [property (db/entity property-id)]
     (p/let [type (get-in property [:block/schema :type])
             type-changed? (and type (:type property-schema) (not= type (:type property-schema)))
-            property-values (db-async/<get-block-property-values repo property-uuid)]
+            property-values (db-async/<get-block-property-values repo property-id)]
       (when (or (not type-changed?)
                 ;; only change type if property hasn't been used yet
                 (and (not (ldb/built-in? (db/get-db) property)) (empty? property-values)))
-        (let [tx-data (cond-> (merge {:block/uuid property-uuid} properties)
+        (let [tx-data (cond-> (merge {:db/ident property-id} properties)
                         property-name (merge
                                        {:block/original-name property-name})
                         property-schema (assoc :block/schema