diff --git a/deps/db/src/logseq/db/schema.cljs b/deps/db/src/logseq/db/schema.cljs index 906ce3565..fe1b971ae 100644 --- a/deps/db/src/logseq/db/schema.cljs +++ b/deps/db/src/logseq/db/schema.cljs @@ -99,6 +99,9 @@ ;; block's file :block/file {:db/valueType :db.type/ref} + ;; latest tx that affected the block + :block/tx-id {} + ;; file :file/path {:db/unique :db.unique/identity} ;; only store the content of logseq's files diff --git a/src/main/frontend/components/block.cljs b/src/main/frontend/components/block.cljs index a138bc052..892ca46d3 100644 --- a/src/main/frontend/components/block.cljs +++ b/src/main/frontend/components/block.cljs @@ -2925,19 +2925,7 @@ (defn- block-changed? [old-block new-block] - (let [ks [:block/uuid :block/content :block/collapsed? :block/link - :block/properties :block.temp/bottom? :block.temp/top?]] - (not - (and (= (select-keys old-block ks) - (select-keys new-block ks)) - (= (:db/id (:block/left old-block)) - (:db/id (:block/left new-block))) - (= (:db/id (:block/parent old-block)) - (:db/id (:block/parent new-block))) - (= (map :db/id (:block/_refs old-block)) - (map :db/id (:block/_refs new-block))) - (= (map :db/id (:block/_parent old-block)) - (map :db/id (:block/_parent new-block))))))) + (not= (:block/tx-id old-block) (:block/tx-id new-block))) (rum/defcs block-container < rum/reactive (rum/local false ::show-block-left-menu?) @@ -2962,16 +2950,6 @@ ::control-show? (atom false) ::navigating-block (atom (:block/uuid block)) ::blocks-container-id container-id)))) - :should-update (fn [old-state new-state] - (let [config-compare-keys [:show-cloze? :hide-children? :own-order-list-type :own-order-list-index] - b1 (second (:rum/args old-state)) - b2 (second (:rum/args new-state)) - result (or - (block-changed? b1 b2) - ;; config changed - (not= (select-keys (first (:rum/args old-state)) config-compare-keys) - (select-keys (first (:rum/args new-state)) config-compare-keys)))] - (boolean result))) :will-unmount (fn [state] ;; restore root block's collapsed state (let [[config block] (:rum/args state) @@ -2987,27 +2965,19 @@ edit-input-id (str "edit-block-" blocks-container-id "-" (:block/uuid block)) edit? (state/sub [:editor/editing? edit-input-id]) opts {:edit? edit? - :edit-input-id edit-input-id} - ref? (:ref? config) - custom-query? (boolean (:custom-query? config))] + :edit-input-id edit-input-id}] (cond unloaded? [:div.ls-block.flex-1.flex-col.rounded-sm {:style {:width "100%"}} - [:div.flex.flex-row - [:div.flex.flex-row.items-center.mr-2.ml-1 {:style {:height 24}} - [:span.bullet-container.cursor - [:span.bullet]]] - [:div.flex.flex-1 - [:span.opacity-70 - "Loading..."]]]] + [:div.flex.flex-row + [:div.flex.flex-row.items-center.mr-2.ml-1 {:style {:height 24}} + [:span.bullet-container.cursor + [:span.bullet]]] + [:div.flex.flex-1 + [:span.opacity-70 + "Loading..."]]]] :else - (if (or ref? custom-query? (:lazy? config)) - (ui/lazy-visible - (fn [] (block-container-inner state repo config block opts)) - {:debug-id (str "block-container-ref " (:db/id block)) - :fade-in? false - :initial-state edit?}) - (block-container-inner state repo config block opts))))) + (block-container-inner state repo config block opts)))) (defn divide-lists [[f & l]] @@ -3377,31 +3347,56 @@ [config col] (map #(markup-element-cp config %) col)) -(defn- block-item - [config blocks idx item] +(rum/defc block-item < + {:should-update (fn [old-state new-state] + (let [config-compare-keys [:show-cloze? :hide-children? :own-order-list-type :own-order-list-index] + b1 (second (:rum/args old-state)) + b2 (second (:rum/args new-state)) + result (or + (block-changed? b1 b2) + ;; config changed + (not= (select-keys (first (:rum/args old-state)) config-compare-keys) + (select-keys (first (:rum/args new-state)) config-compare-keys)))] + (boolean result)))} + [config item {:keys [top? bottom?]}] (let [original-block item linked-block (:block/link item) item (or linked-block item) item (cond-> (dissoc item :block/meta) (not (:block-children? config)) - (assoc :block.temp/top? (zero? idx) - :block.temp/bottom? (= (count blocks) (inc idx)))) - config (assoc config :block/uuid (:block/uuid item) - :idx idx) + (assoc :block.temp/top? top? + :block.temp/bottom? bottom?)) + config (assoc config :block/uuid (:block/uuid item)) config' (if linked-block (assoc config :original-block original-block) - config)] - (rum/with-key (block-container config' item) - (str (:blocks-container-id config') - "-" - (:block/uuid item) - (when linked-block - (str "-" (:block/uuid original-block))))))) + config) + ref? (:ref? config) + custom-query? (boolean (:custom-query? config)) + lazy? (:lazy? config) + cp-f (fn [] + (rum/with-key (block-container config' item) + (str (:blocks-container-id config') + "-" + (:block/uuid item) + (when linked-block + (str "-" (:block/uuid original-block))))))] + (if (or ref? custom-query? lazy?) + (ui/lazy-visible cp-f + {:debug-id (str "block-container-ref " (:db/id item)) + :fade-in? false}) + (cp-f)))) (defn- block-list [config blocks] (for [[idx item] (medley/indexed blocks)] - (block-item config blocks idx item))) + (let [top? (zero? idx) + bottom? (= (count blocks) (inc idx))] + (rum/with-key + (block-item (assoc config :idx idx) item {:top? top? + :bottom? bottom?}) + (str "blocks-" (:blocks-container-id config) + "-" + (:block/uuid item)))))) (rum/defcs blocks-container < {:init (fn [state] (assoc state ::init-blocks-container-id (atom nil)))} diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index 4fc7df070..738e6ba79 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -147,9 +147,7 @@ (and (not block?) - (empty? (:block/_parent block)) - - ) + (empty? (:block/_parent block))) (dummy-block page-name) :else @@ -164,7 +162,7 @@ hiccup-config (common-handler/config-with-document-mode hiccup-config) blocks (if block? [block] (db/sort-by-left (:block/_parent block) block)) non-collapsed-blocks-count (count (remove :block/collapsed? (:block/_page (db/entity (:db/id page-e))))) - lazy? (> non-collapsed-blocks-count 300) + lazy? (> non-collapsed-blocks-count 50) hiccup (component-block/->hiccup blocks (assoc hiccup-config :lazy? lazy?) {})] [:div (page-blocks-inner page-name block hiccup sidebar? whiteboard? block-id) diff --git a/src/main/frontend/db/react.cljs b/src/main/frontend/db/react.cljs index 77f4ec27c..bb413128d 100644 --- a/src/main/frontend/db/react.cljs +++ b/src/main/frontend/db/react.cljs @@ -227,10 +227,10 @@ (map :e)) blocks (-> (concat blocks other-blocks) distinct) block-entities (keep (fn [block-id] - (let [block-id (if (and (string? block-id) (util/uuid-string? block-id)) - [:block/uuid block-id] - block-id)] - (db-utils/entity block-id))) blocks) + (let [block-id (if (and (string? block-id) (util/uuid-string? block-id)) + [:block/uuid block-id] + block-id)] + (db-utils/entity block-id))) blocks) affected-keys (concat (mapcat (fn [block] diff --git a/src/main/frontend/modules/outliner/pipeline.cljs b/src/main/frontend/modules/outliner/pipeline.cljs index fe3d47875..b8bff8347 100644 --- a/src/main/frontend/modules/outliner/pipeline.cljs +++ b/src/main/frontend/modules/outliner/pipeline.cljs @@ -114,7 +114,15 @@ (react/refresh! repo tx-report')) (when (and (config/db-based-graph? repo) (not (:skip-persist? tx-meta))) - (let [upsert-blocks (outliner-pipeline/build-upsert-blocks blocks deleted-block-uuids (:db-after tx-report'))] + (let [upsert-blocks (outliner-pipeline/build-upsert-blocks blocks deleted-block-uuids (:db-after tx-report')) + updated-blocks (remove (fn [b] (contains? (set deleted-block-uuids) (:block/uuid b))) blocks) + tx-id (get-in tx-report' [:tempids :db/current-tx]) + update-tx-ids (map (fn [b] + (when-let [db-id (:db/id b)] + {:db/id db-id + :block/tx-id tx-id})) updated-blocks)] + (when (seq update-tx-ids) + (db/transact! repo update-tx-ids {:replace? true})) (p/let [_transact-result (persist-db/= (- now last-time) 3000))))) diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index 7f53a488a..b9a536209 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -1118,15 +1118,18 @@ (rum/defc lazy-loading-placeholder [height] - [:div.shadow.rounded-md.p-4.w-full.mx-auto.mb-5.opacity-70 {:style {:height height}} - [:div.animate-pulse.flex.space-x-4 - [:div.flex-1.space-y-3.py-1 - [:div.h-2.rounded] - [:div.space-y-3 - [:div.grid.grid-cols-3.gap-4 - [:div.h-2.rounded.col-span-2] - [:div.h-2.rounded.col-span-1]] - [:div.h-2.rounded]]]]]) + [:div {:style {:height height}}] + ;; [:div.shadow.rounded-md.p-4.w-full.mx-auto.mb-5.opacity-70 {:style {:height height}} + ;; ;; [:div.animate-pulse.flex.space-x-4 + ;; ;; [:div.flex-1.space-y-3.py-1 + ;; ;; [:div.h-2.rounded] + ;; ;; [:div.space-y-3 + ;; ;; [:div.grid.grid-cols-3.gap-4 + ;; ;; [:div.h-2.rounded.col-span-2] + ;; ;; [:div.h-2.rounded.col-span-1]] + ;; ;; [:div.h-2.rounded]]]] + ;; ] + ) (rum/defc lazy-visible-inner [visible? content-fn ref fade-in?]