File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 [logseq.db.frontend.property :as db-property]))
88
99(defn remove-conflict-same-block-datoms
10- " remove conflict entity-datoms for same-block(same block/uuid) in same-entity-datoms-coll.
11- merge
12- [[[182 :block/uuid block-uuid1 1 false], ...]
13- [[183 :block/uuid block-uuid1 1 true], ...]]
14- into
15- [[[183 :block/uuid block-uuid1 1 true], ...]]
16- "
10+ " remove conflict entity-datoms for same-block(same block/uuid) in same-entity-datoms-coll."
1711 [same-entity-datoms-coll]
1812 (let [entity-info (map (fn [datoms]
1913 (let [first-datom (first datoms)
2014 e (nth first-datom 0 )
2115 t (nth first-datom 3 )
22- uuid (some (fn [d]
16+ uuid-datom (some (fn [d]
2317 (when (keyword-identical? :block/uuid (nth d 1 ))
24- (nth d 2 )))
25- datoms)]
26- {:e e :t t :uuid uuid :datoms datoms}))
18+ d))
19+ datoms)
20+ uuid (when uuid-datom (nth uuid-datom 2 ))
21+ added? (when uuid-datom (nth uuid-datom 4 ))]
22+ {:e e :t t :uuid uuid :added? added? :datoms datoms}))
2723 same-entity-datoms-coll)
2824 uuid-groups (group-by :uuid (filter :uuid entity-info))
2925 loser-eids (reduce
3228 (reduce
3329 (fn [acc* [_t infos*]]
3430 (if (> (count infos*) 1 )
35- (let [sorted-infos (sort-by :e > infos*)
31+ (let [sorted-infos (sort-by (fn [x] [(if (:added? x) 1 0 ) (:e x)])
32+ (fn [a b] (compare b a))
33+ infos*)
3634 losers (rest sorted-infos)]
3735 (into acc* (map :e losers)))
3836 acc*))
Original file line number Diff line number Diff line change 228228 result (subject/remove-conflict-same-block-datoms same-entity-datoms-coll)]
229229 (is (= 2 (count result)))
230230 (is (= datoms-1 (first result)))
231- (is (= datoms-3 (second result))))))
231+ (is (= datoms-3 (second result)))))
232+
233+ (testing " remove conflict entity-datoms should prefer add over retract"
234+ (let [block-uuid1 #uuid " aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
235+ datoms-1 [[100 :block/uuid block-uuid1 1 true ]]
236+ datoms-2 [[101 :block/uuid block-uuid1 1 false ]]
237+ same-entity-datoms-coll [datoms-1 datoms-2]
238+ result (subject/remove-conflict-same-block-datoms same-entity-datoms-coll)]
239+ (is (= 1 (count result)))
240+ (is (= datoms-1 (first result))))))
You can’t perform that action at this time.
0 commit comments