mirror of
https://github.com/logseq/logseq.git
synced 2026-06-01 19:01:22 +00:00
fix lint warnings
This commit is contained in:
@@ -104,24 +104,6 @@
|
||||
(log/error :nfs/load-files-error repo-url)
|
||||
(log/error :exception error))))))
|
||||
|
||||
(defn- remove-non-exists-refs!
|
||||
[data]
|
||||
(let [block-ids (->> (map :block/uuid data)
|
||||
(remove nil?)
|
||||
(set))
|
||||
keep-block-ref-f (fn [refs]
|
||||
(filter (fn [ref]
|
||||
(cond
|
||||
(and (vector? ref) (= :block/uuid (first ref)))
|
||||
(let [id (second ref)]
|
||||
(or (contains? block-ids id)
|
||||
(db/entity [:block/uuid id])))
|
||||
:else
|
||||
true)) refs))]
|
||||
(map (fn [item]
|
||||
(update item :block/refs keep-block-ref-f))
|
||||
data)))
|
||||
|
||||
(defn- page-exists-in-another-file
|
||||
"Conflict of files towards same page"
|
||||
[repo-url page file]
|
||||
@@ -159,41 +141,41 @@
|
||||
new? (nil? (db/entity [:file/path file]))]
|
||||
(db/set-file-content! repo-url file content)
|
||||
(let [format (format/get-format file)
|
||||
file-content [{:file/path file}]]
|
||||
(let [tx (if (contains? config/mldoc-support-formats format)
|
||||
(let [[pages blocks] (extract-handler/extract-blocks-pages repo-url file content)
|
||||
first-page (first pages)
|
||||
delete-blocks (->
|
||||
(concat
|
||||
(db/delete-file-blocks! repo-url file)
|
||||
(when first-page (db/delete-page-blocks repo-url (:block/name first-page))))
|
||||
(distinct))
|
||||
_ (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)]
|
||||
(state/pub-event! [:notification/show
|
||||
{:content error
|
||||
:status :error
|
||||
:clear? false}]))))
|
||||
block-ids (map (fn [block] {:block/uuid (:block/uuid block)}) blocks)
|
||||
block-refs-ids (->> (mapcat :block/refs blocks)
|
||||
(filter (fn [ref] (and (vector? ref)
|
||||
(= :block/uuid (first ref)))))
|
||||
(map (fn [ref] {:block/uuid (second ref)}))
|
||||
(seq))
|
||||
;; To prevent "unique constraint" on datascript
|
||||
block-ids (set/union (set block-ids) (set block-refs-ids))
|
||||
pages (extract-handler/with-ref-pages pages blocks)
|
||||
pages-index (map #(select-keys % [:block/name]) pages)]
|
||||
;; does order matter?
|
||||
(concat file-content pages-index delete-blocks pages block-ids blocks))
|
||||
file-content)]
|
||||
(let [tx (concat tx [(let [t (tc/to-long (t/now))] ;; TODO: use file system timestamp?
|
||||
(cond->
|
||||
{:file/path file}
|
||||
new?
|
||||
(assoc :file/created-at t)))])]
|
||||
(db/transact! repo-url tx (when new-graph? {:new-graph? true}))))))))
|
||||
file-content [{:file/path file}]
|
||||
tx (if (contains? config/mldoc-support-formats format)
|
||||
(let [[pages blocks] (extract-handler/extract-blocks-pages repo-url file content)
|
||||
first-page (first pages)
|
||||
delete-blocks (->
|
||||
(concat
|
||||
(db/delete-file-blocks! repo-url file)
|
||||
(when first-page (db/delete-page-blocks repo-url (:block/name first-page))))
|
||||
(distinct))
|
||||
_ (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)]
|
||||
(state/pub-event! [:notification/show
|
||||
{:content error
|
||||
:status :error
|
||||
:clear? false}]))))
|
||||
block-ids (map (fn [block] {:block/uuid (:block/uuid block)}) blocks)
|
||||
block-refs-ids (->> (mapcat :block/refs blocks)
|
||||
(filter (fn [ref] (and (vector? ref)
|
||||
(= :block/uuid (first ref)))))
|
||||
(map (fn [ref] {:block/uuid (second ref)}))
|
||||
(seq))
|
||||
;; To prevent "unique constraint" on datascript
|
||||
block-ids (set/union (set block-ids) (set block-refs-ids))
|
||||
pages (extract-handler/with-ref-pages pages blocks)
|
||||
pages-index (map #(select-keys % [:block/name]) pages)]
|
||||
;; does order matter?
|
||||
(concat file-content pages-index delete-blocks pages block-ids blocks))
|
||||
file-content)
|
||||
tx (concat tx [(let [t (tc/to-long (t/now))] ;; TODO: use file system timestamp?
|
||||
(cond->
|
||||
{:file/path file}
|
||||
new?
|
||||
(assoc :file/created-at t)))])]
|
||||
(db/transact! repo-url tx (when new-graph? {:new-graph? true}))))))
|
||||
|
||||
;; TODO: Remove this function in favor of `alter-files`
|
||||
(defn alter-file
|
||||
@@ -208,24 +190,24 @@
|
||||
#(fs/write-file! repo (config/get-repo-dir repo) path content
|
||||
(assoc (when original-content {:old-content original-content})
|
||||
:skip-compare? skip-compare?)))]
|
||||
(let [_ (if reset?
|
||||
(do
|
||||
(when-let [page-id (db/get-file-page-id path)]
|
||||
(db/transact! repo
|
||||
[[:db/retract page-id :block/alias]
|
||||
[:db/retract page-id :block/tags]]))
|
||||
(reset-file! repo path content new-graph?))
|
||||
(db/set-file-content! repo path content))]
|
||||
(util/p-handle (write-file!)
|
||||
(fn [_]
|
||||
(when (= path (config/get-config-path repo))
|
||||
(restore-config! repo true))
|
||||
(when (= path (config/get-custom-css-path repo))
|
||||
(ui-handler/add-style-if-exists!))
|
||||
(when re-render-root? (ui-handler/re-render-root!)))
|
||||
(fn [error]
|
||||
(println "Write file failed, path: " path ", content: " content)
|
||||
(log/error :write/failed error))))))
|
||||
(if reset?
|
||||
(do
|
||||
(when-let [page-id (db/get-file-page-id path)]
|
||||
(db/transact! repo
|
||||
[[:db/retract page-id :block/alias]
|
||||
[:db/retract page-id :block/tags]]))
|
||||
(reset-file! repo path content new-graph?))
|
||||
(db/set-file-content! repo path content))
|
||||
(util/p-handle (write-file!)
|
||||
(fn [_]
|
||||
(when (= path (config/get-config-path repo))
|
||||
(restore-config! repo true))
|
||||
(when (= path (config/get-custom-css-path repo))
|
||||
(ui-handler/add-style-if-exists!))
|
||||
(when re-render-root? (ui-handler/re-render-root!)))
|
||||
(fn [error]
|
||||
(println "Write file failed, path: " path ", content: " content)
|
||||
(log/error :write/failed error)))))
|
||||
|
||||
(defn set-file-content!
|
||||
[repo path new-content]
|
||||
|
||||
Reference in New Issue
Block a user