Răsfoiți Sursa

enhance(perf): sort view data using datoms when possible

Tienson Qin 8 luni în urmă
părinte
comite
0047730991
1 a modificat fișierele cu 19 adăugiri și 22 ștergeri
  1. 19 22
      deps/db/src/logseq/db/common/view.cljs

+ 19 - 22
deps/db/src/logseq/db/common/view.cljs

@@ -87,28 +87,25 @@
                              reverse)
 
                            :else
-                           (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))
-                           ;;     ))
-                           )
+                           (let [ref-type? (= :db.type/ref (:db/valueType property))]
+                             (if (or ref-type? (not (contains?
+                                                     #{:block/updated-at :block/created-at :block/title}
+                                                     (:db/ident property))))
+                               (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)))))
+
                          distinct)]
     (if partition?
       (partition-by get-value-fn sorted-entities)