Browse Source

fix: deadline query doesn't work for db graphs

Fixes LOG-3245
Gabriel Horner 1 year ago
parent
commit
f5666fab47
2 changed files with 41 additions and 25 deletions
  1. 40 24
      src/main/frontend/db/async.cljs
  2. 1 1
      src/main/frontend/db/query_dsl.cljs

+ 40 - 24
src/main/frontend/db/async.cljs

@@ -232,30 +232,46 @@
           future-day (some->> (t/plus current-day (t/days future-days))
                               (tf/unparse date-format)
                               (parse-long))]
-      (when future-day
-        (when-let [repo (state/get-current-repo)]
-          (p/let [result (<q repo {}
-                             '[:find [(pull ?block ?block-attrs) ...]
-                               :in $ ?day ?future ?block-attrs
-                               :where
-                               (or
-                                [?block :block/scheduled ?d]
-                                [?block :block/deadline ?d])
-                               [(get-else $ ?block :block/repeated? false) ?repeated]
-                               [(get-else $ ?block :block/marker "NIL") ?marker]
-                               [(not= ?marker "DONE")]
-                               [(not= ?marker "CANCELED")]
-                               [(not= ?marker "CANCELLED")]
-                               [(<= ?d ?future)]
-                               (or-join [?repeated ?d ?day]
-                                        [(true? ?repeated)]
-                                        [(>= ?d ?day)])]
-                             date
-                             future-day
-                             db-model/file-graph-block-attrs)]
-            (->> result
-                 db-model/sort-by-order-recursive
-                 db-utils/group-by-page)))))))
+      (when-let [repo (and future-day (state/get-current-repo))]
+        (p/let [result
+                (if (config/db-based-graph? repo)
+                  (<q repo {}
+                      '[:find [(pull ?block ?block-attrs) ...]
+                        :in $ ?day ?future ?block-attrs
+                        :where
+                        [?block :logseq.task/deadline ?deadline]
+                        [?deadline :block/journal-day ?d]
+                        [?block :logseq.task/status ?status]
+                        [?status :db/ident ?status-ident]
+                        [(not= ?status-ident :logseq.task/status.done)]
+                        [(not= ?status-ident :logseq.task/status.canceled)]
+                        [(<= ?d ?future)]
+                        [(>= ?d ?day)]]
+                      date
+                      future-day
+                      '[*])
+                  (<q repo {}
+                      '[:find [(pull ?block ?block-attrs) ...]
+                        :in $ ?day ?future ?block-attrs
+                        :where
+                        (or
+                         [?block :block/scheduled ?d]
+                         [?block :block/deadline ?d])
+                        [(get-else $ ?block :block/repeated? false) ?repeated]
+                        [(get-else $ ?block :block/marker "NIL") ?marker]
+                        [(not= ?marker "DONE")]
+                        [(not= ?marker "CANCELED")]
+                        [(not= ?marker "CANCELLED")]
+                        [(<= ?d ?future)]
+                        (or-join [?repeated ?d ?day]
+                                 [(true? ?repeated)]
+                                 [(>= ?d ?day)])]
+                      date
+                      future-day
+                      db-model/file-graph-block-attrs))]
+          (->> result
+               db-model/sort-by-order-recursive
+               db-utils/group-by-page))))))
 
 (defn <get-tag-pages
   [graph tag-id]

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

@@ -726,7 +726,7 @@ Some bindings in this fn:
     (pre-transform q')))
 
 (def db-block-attrs
-  "Like ldb/block-attrs but for query dsl an db graphs"
+  "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]}