fix: task sort by scheduled field make empty rows disappeared

fixes https://github.com/logseq/db-test/issues/315
This commit is contained in:
Tienson Qin
2025-06-12 19:26:42 +08:00
parent 692b518a4d
commit 1cac99d0c0

View File

@@ -86,28 +86,29 @@
(not asc?)
reverse)
(not (ldb/db-based-graph? db)) ; file graph properties don't support index
(sort (common-util/by-sorting
[{:get-value get-value-fn
:asc? asc?}]) entities)
:else
(let [ref-type? (= :db.type/ref (:db/valueType property))]
(if ref-type?
(sort-ref-entities-by-single-property entities sorting get-value-fn)
(let [datoms (cond->
(->> (d/datoms db :avet id)
(common-util/distinct-by :e)
vec)
(not asc?)
rseq)
row-ids (set (map :db/id entities))
id->row (zipmap (map :db/id entities) entities)]
(keep
(fn [d]
(when (row-ids (:e d))
(id->row (:e d))))
datoms)))))
(sort-ref-entities-by-single-property entities sorting get-value-fn)
;; (let [ref-type? (= :db.type/ref (:db/valueType property))]
;; (if ref-type?
;; (sort-ref-entities-by-single-property entities sorting get-value-fn)
;; ;; FIXME: entity may not have the value
;; ;; (let [datoms (cond->
;; ;; (->> (d/datoms db :avet id)
;; ;; (common-util/distinct-by :e)
;; ;; vec)
;; ;; (not asc?)
;; ;; rseq)
;; ;; row-ids (set (map :db/id entities))
;; ;; id->row (zipmap (map :db/id entities) entities)]
;; ;; (keep
;; ;; (fn [d]
;; ;; (when (row-ids (:e d))
;; ;; (id->row (:e d))))
;; ;; datoms))
;; ))
)
distinct)]
(if partition?
(partition-by get-value-fn sorted-entities)
@@ -132,6 +133,8 @@
minor-sorting (seq (rest sorting))
major-sorted-entities
(sort-by-single-property db major-sorting entities (not-empty minor-sorting))]
(prn :debug :count (count entities)
:sorted (count major-sorted-entities))
(if minor-sorting
(sort-entities-by-minor-sorting db major-sorted-entities minor-sorting)
major-sorted-entities)))