diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index 4ba2b93de7..2927a722f2 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -1351,7 +1351,6 @@ (try (let [now (tc/to-long (t/now)) [block-refs blocks] (block/extract-blocks ast (utf8/length utf8-content) utf8-content) - _ (transact! repo-url block-refs) pages (pages-fn blocks ast) ref-pages (atom #{}) ref-tags (atom #{}) @@ -1450,11 +1449,9 @@ {:page/original-name page :page/name (string/lower-case page)}) @ref-pages))] - (vec - (->> (concat - pages - blocks) - (remove nil?)))) + [(remove nil? pages) + (remove nil? block-refs) + (remove nil? blocks)]) (catch js/Error e (js/console.log e)))) @@ -1470,16 +1467,6 @@ properties))] (into {} properties))) -(defn monthly-journals-exists? - [current-repo] - (when-let [files (seq (->> (get-files current-repo) - (map first) - (remove nil?)))] - (some - (fn [file] (re-find #"journals/[0-9]{4}_[0-9]{2}\.+" file)) - files))) - -;; check journal formats and report errors (defn extract-blocks-pages [repo-url file content utf8-content] (if (string/blank? content) @@ -1493,60 +1480,26 @@ (= "Properties" (ffirst first-block)) (last (first first-block)))] (if (and properties (seq properties)) - properties)) - monthly? (re-find #"journals/[0-9]{4}_[0-9]{2}\.+" file)] - (cond - (and journal? monthly?) - (extract-pages-and-blocks - repo-url - format ast properties - file content utf8-content true - (fn [blocks _ast] - (let [property-title (:title properties)] - (loop [pages {} - last-page-name nil - blocks blocks] - (if (seq blocks) - (let [[{:block/keys [level title] :as block} & tl] blocks] - (if (or - (and (= level 1) - (when-let [title (last (first title))] - (date/valid-journal-title? title))) - (and property-title (date/valid-journal-title? property-title))) - (let [page-name (or property-title (last (first title))) - new-pages (assoc pages page-name [block])] - (recur new-pages page-name tl)) - (let [new-pages (update pages last-page-name (fn [blocks] - (vec (conj blocks block))))] - (recur new-pages last-page-name tl)))) - pages))))) - - (and journal? (not monthly?)) - (extract-pages-and-blocks - repo-url - format ast properties - file content utf8-content true - (fn [blocks ast] - [[(get-page-name file ast) blocks]])) - - (not journal?) - (extract-pages-and-blocks - repo-url - format ast properties - file content utf8-content false - (fn [blocks ast] - [[(get-page-name file ast) blocks]])))))) + properties))] + (extract-pages-and-blocks + repo-url + format ast properties + file content utf8-content journal? + (fn [blocks ast] + [[(get-page-name file ast) blocks]]))))) (defn extract-all-blocks-pages [repo-url contents] - (vec - (mapcat - (fn [[file content] contents] - (println "Parsing : " file) - (when content - (let [utf8-content (utf8/encode content)] - (extract-blocks-pages repo-url file content utf8-content)))) - contents))) + (let [result (map + (fn [[file content] contents] + (println "Parsing : " file) + (when content + (let [utf8-content (utf8/encode content)] + (extract-blocks-pages repo-url file content utf8-content)))) + contents)] + ;; '(pages block-refs blocks) + (->> (apply map concat result) + (apply concat)))) ;; TODO: compare blocks (defn reset-file! @@ -1558,8 +1511,8 @@ file-content [{:file/path file}] tx (if (contains? config/mldoc-support-formats format) (let [delete-blocks (delete-file-blocks! repo-url file) - blocks-pages (extract-blocks-pages repo-url file content utf8-content)] - (concat file-content delete-blocks blocks-pages)) + [pages block-refs blocks] (extract-blocks-pages repo-url file content utf8-content)] + (concat file-content delete-blocks pages block-refs blocks)) file-content) tx (concat tx [(let [t (tc/to-long (t/now))] (cond-> diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index f0526422e5..d8cd794be8 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -8,7 +8,6 @@ [cljs-bean.core :as bean] [frontend.date :as date] [frontend.handler.notification :as notification] - [frontend.handler.migration :as migration-handler] [frontend.handler.repo :as repo-handler] [frontend.handler.file :as file-handler] [frontend.handler.ui :as ui-handler] @@ -49,7 +48,6 @@ (not (seq (db/get-files config/local-repo)))) (repo-handler/setup-local-repo-if-not-exists!) (state/set-db-restoring! false)) - (migration-handler/show!) (if (seq (:repos me)) ;; FIXME: handle error (repo-handler/request-app-tokens! diff --git a/src/main/frontend/handler/migration.cljs b/src/main/frontend/handler/migration.cljs deleted file mode 100644 index d876a288d3..0000000000 --- a/src/main/frontend/handler/migration.cljs +++ /dev/null @@ -1,74 +0,0 @@ -(ns frontend.handler.migration - (:require [frontend.handler.notification :as notification] - [frontend.db :as db] - [frontend.ui :as ui] - [promesa.core :as p] - [frontend.util :as util] - [clojure.string :as str] - [frontend.date :as date] - [frontend.config :as config] - [frontend.state :as state] - [frontend.handler.ui :as ui-handler] - [frontend.handler.file :as file-handler] - [frontend.handler.git :as git-handler] - [frontend.fs :as fs])) - -(defn get-files-from-blocks - [blocks] - (if (<= (count (:page blocks)) 1) - nil - {:path (str config/default-journals-directory "/" (date/journal-title->default (:title blocks)) "." (config/get-file-extension (state/get-preferred-format))) - :page (reduce #(if (not (str/blank? (:block/content %2))) (str %1 (:block/content %2)) %1) "" (:page blocks))})) - -(defn handle-journal-migration-from-monthly-to-daily! - [repo] - (state/set-daily-migrating! true) - (let [all-journals (->> - (db/q repo [:journals] {:use-cache? false} - '[:find ?page-name - :where - [?page :page/journal? true] - [?page :page/original-name ?page-name]]) - (db/react) - (map first) - (distinct) - (map (fn [el] {:title el :page (db/get-page-blocks repo el)})) - (util/remove-nils) - (map get-files-from-blocks) - (remove nil?)) - all-files (map first (db/get-files repo))] - (let [to-delete (filter #(re-find #"journals/[0-9]{4}_[0-9]{2}\.+" %) all-files)] - (-> (p/all (doall (map (fn [{:keys [path page]}] - (println "migrating" path) - (p/let [file-exists? (fs/create-if-not-exists (util/get-repo-dir repo) path page)] - (db/reset-file! repo path page) - (git-handler/git-add repo path))) all-journals))) - (p/then - (fn [_result] - (let [remove-files (doall (map (fn [path] - (db/delete-file! repo path) - (file-handler/remove-file! repo path)) to-delete))] - (-> (p/all remove-files) - (p/then (fn [result] - (println "Migration successfully!") - (state/set-daily-migrating! false) - (ui-handler/re-render-root!) - (notification/show! - "Migration successfully! Please re-index your repository after the sync indicator turned green for a smooth experience." - :success))) - (p/catch (fn [error] - (state/set-daily-migrating! false) - (println "Migration failed: ") - (js/console.dir error))))))))))) - -(defn show! - [] - (when-let [current-repo (state/get-current-repo)] - (when (db/monthly-journals-exists? current-repo) - (notification/show! - [:div - [:p "Logseq is migrating to creating journal pages on a daily basis for better performance and data safety. In the future, the current method of storing journal files once a month would be removed. Please click the following button to migrate, and feel free to let us know if anything unexpected happened!"] - (ui/button "Begin migration" - :on-click #(handle-journal-migration-from-monthly-to-daily! current-repo))] - :warning - false)))) diff --git a/src/main/frontend/handler/repo.cljs b/src/main/frontend/handler/repo.cljs index ba3c23b0f0..8124e1dbc2 100644 --- a/src/main/frontend/handler/repo.cljs +++ b/src/main/frontend/handler/repo.cljs @@ -14,7 +14,6 @@ [frontend.handler.ui :as ui-handler] [frontend.handler.git :as git-handler] [frontend.handler.file :as file-handler] - [frontend.handler.migration :as migration-handler] [frontend.handler.notification :as notification] [frontend.handler.route :as route-handler] [frontend.handler.common :as common-handler] @@ -257,9 +256,7 @@ (defn load-db-and-journals! [repo-url diffs first-clone?] (when (or diffs first-clone?) - (p/let [_ (load-repo-to-db! repo-url diffs first-clone?)] - (when first-clone? - (migration-handler/show!))))) + (load-repo-to-db! repo-url diffs first-clone?))) (defn transact-react-and-alter-file! [repo tx transact-option files] diff --git a/src/main/frontend/state.cljs b/src/main/frontend/state.cljs index 59af6e2dfa..6a363a8efd 100644 --- a/src/main/frontend/state.cljs +++ b/src/main/frontend/state.cljs @@ -748,14 +748,6 @@ :modal/show? false :modal/panel-content nil)) -(defn get-journal-basis - [] - (or - (when-let [repo (get-current-repo)] - (when-let [basis (get-in @state [:config repo :journal-basis])] - (keyword (string/lower-case (str basis))))) - :monthly)) - (defn update-repo-last-stored-at! [repo] (swap! state assoc-in [:repo/persist-status repo :last-stored-at] (util/time-ms)))