Browse Source

fix: dedupe too many same page to sync-to-file

rcmerci 2 năm trước cách đây
mục cha
commit
961dde4c90
2 tập tin đã thay đổi với 20 bổ sung1 xóa
  1. 4 1
      src/main/frontend/state.cljs
  2. 16 0
      src/main/frontend/util.cljc

+ 4 - 1
src/main/frontend/state.cljs

@@ -31,7 +31,10 @@
      :today                                 nil
      :system/events                         (async/chan 1000)
      :db/batch-txs                          (async/chan 1000)
-     :file/writes                           (async/chan 10000)
+     :file/writes                           (async/chan 10000
+                                                        (util/dedupe-by
+                                                         (fn [[repo page-id outliner-op _epoch]]
+                                                           [repo page-id outliner-op])))
      :file/unlinked-dirs                    #{}
      :reactive/custom-queries               (async/chan 1000)
      :notification/show?                    false

+ 16 - 0
src/main/frontend/util.cljc

@@ -1513,3 +1513,19 @@ Arg *stop: atom, reset to true to stop the loop"
      (if (satisfies? IMeta o)
        (with-meta o meta)
        o)))
+
+
+(defn dedupe-by
+  ([keyfn]
+   (fn [rf]
+     (let [pa (volatile! ::none)]
+       (fn
+         ([] (rf))
+         ([result] (rf result))
+         ([result input]
+          (let [prior @pa
+                key (keyfn input)]
+            (vreset! pa key)
+            (if (= prior key)
+              result
+              (rf result input)))))))))