|
|
@@ -6,6 +6,7 @@
|
|
|
[frontend.db :as db]
|
|
|
["/frontend/utils" :as utils]
|
|
|
[frontend.mobile.util :as mobile-util]
|
|
|
+ [logseq.db.schema :as db-schema]
|
|
|
[logseq.graph-parser :as graph-parser]
|
|
|
[logseq.graph-parser.util :as gp-util]
|
|
|
[logseq.graph-parser.config :as gp-config]
|
|
|
@@ -19,12 +20,32 @@
|
|
|
(when (not= file current-file)
|
|
|
current-file))))
|
|
|
|
|
|
-(defn- get-delete-blocks [repo-url first-page file]
|
|
|
- (let [delete-blocks (->
|
|
|
- (concat
|
|
|
- (db/delete-file-blocks! repo-url file)
|
|
|
- (when first-page (db/delete-page-blocks repo-url (:block/name first-page))))
|
|
|
- (distinct))]
|
|
|
+(defn- get-clear-blocks-tx
|
|
|
+ [blocks retain-uuids]
|
|
|
+ (let [tx-for-block (fn [block] (let [{uuid :block/uuid eid :db/id} block
|
|
|
+ should-retain? (and uuid (contains? retain-uuids uuid))]
|
|
|
+ (cond
|
|
|
+ should-retain?
|
|
|
+ (map (fn [attr] [:db.fn/retractAttribute eid attr]) db-schema/retract-attributes)
|
|
|
+ :else
|
|
|
+ [[:db.fn/retractEntity eid]])))]
|
|
|
+ (mapcat tx-for-block (distinct blocks)))
|
|
|
+ )
|
|
|
+
|
|
|
+(defn- get-clear-block-tx
|
|
|
+ "Returns the transactional operations to clear blocks belonging to the given
|
|
|
+ page and file.
|
|
|
+
|
|
|
+ Blocks are by default fully deleted via retractEntity. However, a collection
|
|
|
+ of block UUIDs to retain can be passed, and any blocks with matching uuids
|
|
|
+ will instead have their attributes cleared individually via
|
|
|
+ 'retractAttribute'. This will preserve block references to the retained
|
|
|
+ UUIDs."
|
|
|
+ [repo-url first-page file retain-uuid-blocks]
|
|
|
+ (let [pages-to-clear (filter some? [(db/get-file-page file) file])
|
|
|
+ blocks (mapcat (fn [page] (db/get-page-blocks-no-cache repo-url page {:pull-keys [:db/id :block/uuid]})) pages-to-clear)
|
|
|
+ retain-uuids (if (seq retain-uuid-blocks) (set (filter some? (map :block/uuid retain-uuid-blocks))) [])
|
|
|
+ tx (get-clear-blocks-tx blocks retain-uuids)]
|
|
|
(when-let [current-file (page-exists-in-another-file repo-url first-page file)]
|
|
|
(when (not= file current-file)
|
|
|
(let [error (str "Page already exists with another file: " current-file ", current file: " file)]
|
|
|
@@ -32,7 +53,8 @@
|
|
|
{:content error
|
|
|
:status :error
|
|
|
:clear? false}]))))
|
|
|
- delete-blocks))
|
|
|
+ tx
|
|
|
+ ))
|
|
|
|
|
|
(defn reset-file!
|
|
|
"Main fn for updating a db with the results of a parsed file"
|
|
|
@@ -62,7 +84,7 @@
|
|
|
new? (nil? (db/entity [:file/path file]))
|
|
|
options (merge (dissoc options :verbose)
|
|
|
{:new? new?
|
|
|
- :delete-blocks-fn (partial get-delete-blocks repo-url)
|
|
|
+ :delete-blocks-fn (partial get-clear-block-tx repo-url)
|
|
|
:extract-options (merge
|
|
|
{:user-config (state/get-config)
|
|
|
:date-formatter (state/get-date-formatter)
|