Browse Source

Squashed commit of the following:

commit 0df1208ae6ce2a141c9907b3fcc8d87819e1f98b
Author: Tienson Qin <[email protected]>
Date:   Sun Apr 20 19:32:24 2025 +0800

    fix: remove d/store calls

    There's a bug with `d/store`: it doesn't clear `tx-tail` in the conn atom.

commit 7d436cf5ebe43855e67d6abd7a12945dfb987f67
Author: Tienson Qin <[email protected]>
Date:   Sun Apr 20 18:03:23 2025 +0800

    chore: bump datascript

commit 878331c53eaad5509fc17ae6909076baa18dbaa1
Author: Tienson Qin <[email protected]>
Date:   Sun Apr 20 12:30:11 2025 +0800

    fix: block title inline

commit 2a8461b41a9726fd8c4ab14185b7b81dfad46518
Author: Tienson Qin <[email protected]>
Date:   Sun Apr 20 12:17:16 2025 +0800

    fix: no way to edit the query as the settings icon doesn't show up

commit f843df948206583469b0cd60499eb011495ca1bf
Author: Tienson Qin <[email protected]>
Date:   Fri Apr 18 23:41:29 2025 +0800

    fix: empty data not trigger query view re-render

commit 6042c8b112b8bbace5378098b59d3ac69a694cb5
Author: Gabriel Horner <[email protected]>
Date:   Fri Apr 18 09:44:27 2025 -0400

    refactor: keep testing concerns in tests

    Move testing requirement to relevant test to make production code easier
    to maintain. Where possible we should avoid helpers like util/node-test? as
    they couple testing concerns with production code

commit c9177abc9ad4179be9c9b23e604e8cd215d5180f
Author: Tienson Qin <[email protected]>
Date:   Fri Apr 18 15:20:22 2025 +0800

    fix: tests

commit b7c45f881ccd5c3a17654687a6791549a16a190c
Author: Tienson Qin <[email protected]>
Date:   Fri Apr 18 13:19:37 2025 +0800

    fix: don't show query builder for non-query blocks

commit 46bdd1a366213271ead5be98afb50900c161e62f
Author: Tienson Qin <[email protected]>
Date:   Fri Apr 18 13:17:07 2025 +0800

    enhance: set query title && code

commit abf90fbb7d9c5817100d6127e891c7b126f27453
Author: Tienson Qin <[email protected]>
Date:   Fri Apr 18 11:47:26 2025 +0800

    fix: queries don't automatically update

    Fix https://github.com/logseq/db-test/issues/237

    This commit also updates custom queries to only fetch :db/id to
    improve performance.

commit aa45b3fa6cddedadd95b1a7b2a585ed29c8f2c61
Author: Gabriel Horner <[email protected]>
Date:   Fri Apr 18 14:31:00 2025 -0400

    fix(regression): paths of file graph exports

    markdown + opml exports had zipped files several
    directories deep because they used the full path of the graph

commit 63403bd8c59cac39e8306d470a2b8a1297552323
Author: Gabriel Horner <[email protected]>
Date:   Fri Apr 18 12:32:51 2025 -0400

    fix: remove unused workarounds from #11774

    Previous commit fixed these issues

commit 4ad4944b4e53c782fa9073aa73c1a03ab063a678
Author: Gabriel Horner <[email protected]>
Date:   Fri Apr 18 12:29:06 2025 -0400

    fix: for file graphs, tags with blank space in the namespace parent

    creates entities with nil :block/title to be created. This
    created unexpected bugs in the UI e.g. all pages and
    caused duplicate content to appear.
    Example from test graph: 'tags:: [[Some / Namespace ]]'
    Fixes
    https://test.logseq.com/#/page/68017fb5-7b9c-448a-9f64-6bb8d8669396
rcmerci 10 months ago
parent
commit
13d7061f7b

+ 1 - 1
deps.edn

@@ -5,7 +5,7 @@
                                          :sha     "5d672bf84ed944414b9f61eeb83808ead7be9127"}
 
   datascript/datascript                 {:git/url "https://github.com/logseq/datascript" ;; fork
-                                         :sha     "1f84d10df4970f054489b0ee78799f64b8dd4ee2"}
+                                         :sha     "3a41bbcdbe66b328bff36d9efd7548bad47f55b6"}
 
   datascript-transit/datascript-transit {:mvn/version "0.3.0"}
   borkdude/rewrite-edn                  {:mvn/version "0.4.7"}

+ 1 - 1
deps/db/deps.edn

@@ -1,7 +1,7 @@
 {:deps
  ;; These deps are kept in sync with https://github.com/logseq/nbb-logseq/blob/main/bb.edn
  {datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
-                         :sha     "1f84d10df4970f054489b0ee78799f64b8dd4ee2"}
+                         :sha     "3a41bbcdbe66b328bff36d9efd7548bad47f55b6"}
   datascript-transit/datascript-transit {:mvn/version "0.3.0"
                                          :exclusions [datascript/datascript]}
   cljs-bean/cljs-bean         {:mvn/version "1.5.0"}

+ 1 - 1
deps/outliner/deps.edn

@@ -1,7 +1,7 @@
 {:deps
  ;; External deps should be kept in sync with https://github.com/logseq/nbb-logseq/blob/main/bb.edn
  {datascript/datascript {:git/url "https://github.com/logseq/datascript" ;; fork
-                         :sha     "1f84d10df4970f054489b0ee78799f64b8dd4ee2"}
+                         :sha     "3a41bbcdbe66b328bff36d9efd7548bad47f55b6"}
   logseq/db             {:local/root "../db"}
   logseq/graph-parser   {:local/root "../db"}
   com.cognitect/transit-cljs {:mvn/version "0.8.280"}

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

@@ -198,7 +198,8 @@
      [:editor/set-property :block/tags :logseq.class/Query]
      [:editor/set-property :logseq.property/query ""]
      [:editor/set-property-on-block-property :logseq.property/query :logseq.property.node/display-type :code]
-     [:editor/set-property-on-block-property :logseq.property/query :logseq.property.code/lang "clojure"]]
+     [:editor/set-property-on-block-property :logseq.property/query :logseq.property.code/lang "clojure"]
+     [:editor/exit]]
     (->block "query")))
 
 (defn db-based-code-block

+ 73 - 57
src/main/frontend/components/block.cljs

@@ -767,7 +767,7 @@
                                      s (if (and tag? (not (:hide-tag-symbol? config))) (str "#" s) s)]
                                  (if (ldb/page? page-entity)
                                    s
-                                   (block-title config page-entity))))]
+                                   (block-title config page-entity {}))))]
           page-component))]]))
 
 (rum/defc popup-preview-impl
@@ -1262,7 +1262,8 @@
     (if (and block (:block/title block))
       (let [content-cp (block-content (assoc config :block-ref? true :stop-events? stop-inner-events?)
                                       block nil (:block/uuid block)
-                                      (:slide? config))
+                                      (:slide? config)
+                                      nil)
             display-type (:logseq.property.node/display-type block)]
         (if (and display-type (not (contains? #{:quote :math} display-type)))
           content-cp
@@ -2356,15 +2357,57 @@
               "Practice")
              [:div "Practice cards"])])))))))
 
+(rum/defc block-title-aux
+  [config block {:keys [query? *show-query?]}]
+  (let [[hover? set-hover?] (rum/use-state false)
+        blank? (string/blank? (:block/title block))
+        opacity (if hover? "opacity-100" "opacity-0")
+        query (:logseq.property/query block)
+        advanced-query? (and query? (= :code (:logseq.property.node/display-type query)))
+        show-query? (and *show-query? @*show-query?)]
+    [:div
+     {:class (if (and query? blank?)
+               "inline-flex"
+               "inline")
+      :on-mouse-over #(set-hover? true)
+      :on-mouse-out #(set-hover? false)}
+     (cond
+       (and query? (and blank? (or advanced-query? show-query?)))
+       [:span.opacity-75.hover:opacity-100 "Untitled query"]
+       (and query? blank?)
+       (query-builder-component/builder query {})
+       :else
+       [:div.inline (text-block-title config block)])
+     (when query?
+       (ui/tooltip
+        (shui/button
+         {:size :sm
+          :variant :ghost
+          :class (str "ls-small-icon text-muted-foreground ml-2 w-6 h-6 transition-opacity ease-in duration-300 " opacity)
+          :on-pointer-down (fn [e]
+                             (util/stop e)
+                             (when *show-query? (swap! *show-query? not)))}
+         (ui/icon "settings"))
+        [:div.opacity-75 (if show-query?
+                           "Hide query"
+                           "Set query")]))
+     (when-let [property (:logseq.property/created-from-property block)]
+       (when-let [message (when (= :url (:logseq.property/type property))
+                            (first (outliner-property/validate-property-value (db/get-db) property (:db/id block))))]
+         (ui/tooltip
+          (shui/button
+           {:size :sm
+            :variant :ghost
+            :class "ls-type-warning ls-small-icon px-1 !py-0 h-4 ml-1"}
+           (ui/icon "alert-triangle"))
+          [:div.opacity-75 message])))]))
+
 (rum/defc block-title < rum/reactive db-mixins/query
-  [config block]
-  (let [collapsed? (:collapsed? config)
-        block' (db/entity (:db/id block))
+  [config block {:keys [*show-query?]}]
+  (let [block' (db/entity (:db/id block))
         node-display-type (:logseq.property.node/display-type block')
         db (db/get-db)
-        query? (ldb/class-instance? (entity-plus/entity-memoized db :logseq.class/Query) block')
-        query (:logseq.property/query block')
-        advanced-query? (and query? (= :code node-display-type))]
+        query? (ldb/class-instance? (entity-plus/entity-memoized db :logseq.class/Query) block')]
     (cond
       (:raw-title? config)
       (text-block-title (dissoc config :raw-title?) block)
@@ -2384,32 +2427,12 @@
       (= :math node-display-type)
       (latex/latex (:block/title block) true false)
 
-      (and query?
-           collapsed?
-           (not advanced-query?)
-           (string/blank? (:block/title block'))
-           (seq (:block/title query)))
-      (query-builder-component/builder query {})
-
       (seq (:logseq.property/_query block'))
       (query-builder-component/builder block' {})
 
-      (and query? (string/blank? (:block/title block')))
-      [:span.opacity-50 "Set query title"]
-
       :else
-      [:span.w-full
-       (text-block-title config block)
-       (when-let [property (:logseq.property/created-from-property block)]
-         (when-let [message (when (= :url (:logseq.property/type property))
-                              (first (outliner-property/validate-property-value (db/get-db) property (:db/id block))))]
-           (ui/tooltip
-            (shui/button
-             {:size :sm
-              :variant :ghost
-              :class "ls-type-warning px-1 !py-0 h-4 ml-1"}
-             (ui/icon "alert-triangle"))
-            [:div.opacity-75 message])))])))
+      (block-title-aux config block {:query? query?
+                                     :*show-query? *show-query?}))))
 
 (rum/defc span-comma
   []
@@ -2829,7 +2852,7 @@
           (clock/seconds->days:hours:minutes:seconds time-spent))]))))
 
 (rum/defc ^:large-vars/cleanup-todo block-content < rum/reactive
-  [config {:block/keys [uuid] :as block} edit-input-id block-id slide?]
+  [config {:block/keys [uuid] :as block} edit-input-id block-id slide? *show-query?]
   (let [repo (state/get-current-repo)
         db-based? (config/db-based-graph? (state/get-current-repo))
         scheduled (when-not db-based? (:block/scheduled block))
@@ -2908,7 +2931,7 @@
       [:div.flex.flex-row.justify-between.block-content-inner
        (when-not plugin-slotted?
          [:div.block-head-wrap
-          (block-title config block)])
+          (block-title config block {:*show-query? *show-query?})])
 
        (if db-based?
          (task-spent-time-cp block)
@@ -2977,7 +3000,7 @@
 
 (rum/defcs ^:large-vars/cleanup-todo block-content-or-editor < rum/reactive
   (rum/local false ::hover?)
-  [state config {:block/keys [uuid] :as block} {:keys [edit-input-id block-id edit? hide-block-refs-count? refs-count *hide-block-refs?]}]
+  [state config {:block/keys [uuid] :as block} {:keys [edit-input-id block-id edit? hide-block-refs-count? refs-count *hide-block-refs? *show-query?]}]
   (let [format (if (config/db-based-graph? (state/get-current-repo))
                  :markdown
                  (or (:block/format block) :markdown))
@@ -3025,7 +3048,7 @@
                                           (editor-handler/unhighlight-blocks!)
                                           (state/set-editing! edit-input-id content block "" {:db (db/get-db)
                                                                                               :container-id (:container-id config)}))}})
-           (block-content config block edit-input-id block-id slide?))
+           (block-content config block edit-input-id block-id slide? *show-query?))
 
           (when (and (not hide-block-refs-count?)
                      (not named?))
@@ -3383,25 +3406,6 @@
       [block* result]
       [nil result])))
 
-(rum/defc query-property-cp < rum/reactive db-mixins/query
-  [block config collapsed?]
-  (let [block (db/entity (:db/id block))
-        db (db/get-db)
-        query? (ldb/class-instance? (entity-plus/entity-memoized db :logseq.class/Query) block)]
-    (when (and query? (not collapsed?))
-      (let [query-id (:db/id (:logseq.property/query block))
-            query (some-> query-id db/sub-block)
-            advanced-query? (= :code (:logseq.property.node/display-type query))]
-        (cond
-          (and advanced-query? (not collapsed?))
-          [:div.flex.flex-1.my-1 {:style {:margin-left 42}}
-           (src-cp (assoc config :code-block query)
-                   {:language "clojure"})]
-
-          (and (not advanced-query?) (not collapsed?))
-          [:div.my-1 {:style {:margin-left 42}}
-           (block-container (assoc config :property? true) query)])))))
-
 (rum/defcs ^:large-vars/cleanup-todo block-container-inner-aux < rum/reactive db-mixins/query
   {:init (fn [state]
            (let [*ref (atom nil)
@@ -3419,10 +3423,13 @@
              (assoc state
                     ::ref *ref
                     ::hide-block-refs? (atom default-hide?)
+                    ::show-query? (atom false)
                     ::refs-count *refs-count)))}
   [state container-state repo config* block {:keys [navigating-block navigated? editing? selected?] :as opts}]
   (let [*ref (::ref state)
         *hide-block-refs? (get state ::hide-block-refs?)
+        *show-query? (get state ::show-query?)
+        show-query? (rum/react *show-query?)
         *refs-count (get state ::refs-count)
         hide-block-refs? (rum/react *hide-block-refs?)
         refs-count (if (seq (:block/_refs block))
@@ -3607,7 +3614,8 @@
                                          :edit? editing?
                                          :refs-count refs-count
                                          :*hide-block-refs? *hide-block-refs?
-                                         :hide-block-refs-count? hide-block-refs-count?}))])]
+                                         :hide-block-refs-count? hide-block-refs-count?
+                                         :*show-query? *show-query?}))])]
 
          (when (and db-based? (not collapsed?) (not (or table? property?)))
            (block-positioned-properties config block :block-below))]
@@ -3615,15 +3623,23 @@
         (when (and @*show-right-menu? (not in-whiteboard?) (not (or table? property?)))
           (block-right-menu config block editing?))])
 
-     (when-not (:table? config)
-       (query-property-cp block config collapsed?))
-
      (when (and db-based?
                 (or sidebar? (not collapsed?))
                 (not (or table? property?)))
        [:div (when-not (:page-title? config) {:style {:padding-left 45}})
         (db-properties-cp config block {:in-block-container? true})])
 
+     (when (and db-based? show-query? (not (:table? config)))
+       (let [query? (ldb/class-instance? (entity-plus/entity-memoized (db/get-db) :logseq.class/Query) block)
+             query (:logseq.property/query block)
+             advanced-query? (and query? (= :code (:logseq.property.node/display-type query)))]
+         [:div.ml-6.my-1
+          (if advanced-query?
+            (src-cp (assoc config :code-block query) {:language "clojure"})
+            [:div
+             [:div.opacity-75.ml-5.text-sm.mb-1 "Set query:"]
+             (block-container config query)])]))
+
      (when (and (not (or (:table? config) (:property? config)))
                 (not hide-block-refs?)
                 (> refs-count 0)

+ 4 - 2
src/main/frontend/components/block.css

@@ -1008,10 +1008,12 @@ html.is-mac {
   height: 18px;
 }
 
+.ls-small-icon svg {
+    width: 12px;
+    height: 12px;
+}
 .ls-type-warning svg {
   color: var(--rx-gray-09);
-  width: 12px;
-  height: 12px;
 }
 
 .ls-page-title .ls-page-icon svg, .ls-page-title .ls-page-icon button {

+ 5 - 1
src/main/frontend/components/views.cljs

@@ -1793,8 +1793,12 @@
                          (c.m/run-task*
                           (m/sp
                             (let [need-query? (and query? (seq query-entity-ids) (or sorting filters (not (string/blank? input))))]
-                              (if (and query? (not (or sorting filters)) (string/blank? input))
+                              (cond
+                                (and query? (empty? query-entity-ids))
+                                (set-data! nil)
+                                (and query? (not (or sorting filters)) (string/blank? input))
                                 (set-data! query-entity-ids)
+                                :else
                                 (when (or (not query?) need-query?)
                                   (try
                                     (let [{:keys [data ref-pages-count]}

+ 3 - 6
src/main/frontend/db/query_dsl.cljs

@@ -732,10 +732,8 @@ Some bindings in this fn:
 
 (def db-block-attrs
   "Block attributes for db graph queries"
-  ;; '*' needed as we need to pull user properties and don't know their names in advance
-  '[*
-    {:block/page [:db/id :block/name :block/title :block/journal-day]}
-    {:block/_parent ...}])
+  ;; only needs :db/id for query/view
+  [:db/id])
 
 (defn query
   "Runs a dsl query with query as a string. Primary use is from '/query' or '{{query }}'"
@@ -767,8 +765,7 @@ Some bindings in this fn:
                                      :query-string query-string
                                      :rules rules}
                                     (merge
-                                     {:use-cache? false
-                                      :transform-fn transform-fn}
+                                     {:transform-fn transform-fn}
                                      query-opts))))))))
 
 (defn custom-query

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

@@ -198,7 +198,8 @@
            (when (or query query-fn)
              (try
                (let [f #(execute-query! repo-url db (vec (cons repo-url k)) cache)]
-                 (when-not custom?
+                 (if custom?
+                   (async/put! (state/get-reactive-custom-queries-chan) [f query])
                    (f)))
                (catch :default e
                  (js/console.error e)

+ 4 - 15
src/main/frontend/worker/pipeline.cljs

@@ -253,13 +253,7 @@
                                     (when (:block/uuid (d/entity db-after db-id))
                                       {:db/id db-id
                                        :block/tx-id tx-id}))) updated-blocks))))
-          tx-report' (if (seq replace-tx)
-                       (ldb/transact! conn replace-tx {:pipeline-replace? true})
-                       (do
-                         (when-not (or (exists? js/process)
-                                       (::skip-store-conn tx-meta false))
-                           (d/store @conn))
-                         tx-report*))
+          tx-report' (ldb/transact! conn replace-tx {:pipeline-replace? true})
           _ (validate-db! repo conn tx-report* tx-meta context)
           full-tx-data (concat (:tx-data tx-report*)
                                (:tx-data refs-tx-report)
@@ -287,14 +281,9 @@
         (or from-disk? new-graph?)
         (let [{:keys [blocks]} (ds-report/get-blocks-and-pages tx-report)
               path-refs (distinct (compute-block-path-refs-tx tx-report blocks))
-              tx-report' (or
-                          (when (seq path-refs)
-                            (ldb/transact! conn path-refs {:pipeline-replace? true}))
-                          (do
-                            (when-not (or (exists? js/process)
-                                          (::skip-store-conn tx-meta false))
-                              (d/store @conn))
-                            tx-report))
+              tx-report' (if (seq path-refs)
+                           (ldb/transact! conn path-refs {:pipeline-replace? true})
+                           tx-report)
               full-tx-data (concat (:tx-data tx-report) (:tx-data tx-report'))
               final-tx-report (assoc tx-report'
                                      :tx-meta (:tx-meta tx-report)

+ 13 - 3
src/test/frontend/db/query_dsl_test.cljs

@@ -18,6 +18,12 @@
 ;; Test helpers
 ;; ============
 
+(def db-block-attrs
+  ;; '*' needed as we need to pull user properties and don't know their names in advance
+  '[*
+    {:block/page [:db/id :block/name :block/title :block/journal-day]}
+    {:block/_parent ...}])
+
 (def dsl-query*
   "Overrides dsl-query/query with ENV variables. When $EXAMPLE is set, prints query
   result of build query. This is useful for documenting examples and debugging.
@@ -48,10 +54,13 @@
                                     :query (apply list 'has-property (rest (:query m)))}
                                    :else
                                    m)]
-                          m'))]
+                          m'))
+                      query-dsl/db-block-attrs db-block-attrs]
           (apply query-dsl/query args))))
     :else
-    query-dsl/query))
+    (fn dsl-query-star [& args]
+      (with-redefs [query-dsl/db-block-attrs db-block-attrs]
+        (apply query-dsl/query args)))))
 
 (defn- ->smart-query
   "Updates to file version if js/process.env.DB_GRAPH is not set"
@@ -70,7 +79,8 @@
 (defn- custom-query
   [query]
   (db/clear-query-state!)
-  (when-let [result (query-dsl/custom-query test-helper/test-db query {})]
+  (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))))
 
 ;; Tests