Forráskód Böngészése

fix: misleading re-index messages show up in db graphs

re-index a graph should only show up for file graphs.
Also moved db.migrate to file-based since it contains re-index
and multiple file graph query assumptions
Gabriel Horner 1 éve
szülő
commit
15642394fc

+ 2 - 0
scripts/src/logseq/tasks/dev/db_and_file_graphs.clj

@@ -21,6 +21,7 @@
   "Namespaces or parent namespaces _only_ for file graphs"
   (mapv escape-shell-regex
         ["frontend.handler.file-based" "frontend.handler.conversion" "frontend.handler.file-sync"
+         "frontend.db.file-based"
          "frontend.fs"
          "frontend.components.conversion" "frontend.components.file-sync"
          "frontend.util.fs"
@@ -36,6 +37,7 @@
 (def file-graph-paths
   "Paths _only_ for file graphs"
   ["src/main/frontend/handler/file_based" "src/main/frontend/handler/conversion.cljs" "src/main/frontend/handler/file_sync.cljs"
+   "src/main/frontend/db/file_based"
    "src/main/frontend/fs"
    "src/main/frontend/components/conversion.cljs" "src/main/frontend/components/file_sync.cljs"
    "src/main/frontend/util/fs.cljs"

+ 4 - 1
src/main/frontend/components/reference.cljs

@@ -1,5 +1,6 @@
 (ns frontend.components.reference
   (:require [clojure.string :as string]
+            [frontend.config :as config]
             [frontend.components.block :as block]
             [frontend.components.content :as content]
             [frontend.components.editor :as editor]
@@ -252,7 +253,9 @@
 (rum/defc references
   [page-name]
   (ui/catch-error
-   (ui/component-error "Linked References: Unexpected error. Please re-index your graph first.")
+   (ui/component-error (if (config/db-based-graph? (state/get-current-repo))
+                         "Linked References: Unexpected error."
+                         "Linked References: Unexpected error. Please re-index your graph first."))
    (ui/lazy-visible
     (fn []
       (references* page-name))

+ 2 - 2
src/main/frontend/db/migrate.cljs → src/main/frontend/db/file_based/migrate.cljs

@@ -1,5 +1,5 @@
-(ns frontend.db.migrate
-  "Do DB migration, in a version-by-version style.
+(ns frontend.db.file-based.migrate
+  "Do DB migration for file graphs, in a version-by-version style.
 
    `:schema/version` is not touched"
   (:require [clojure.string :as string]

+ 3 - 1
src/main/frontend/db/model.cljs

@@ -676,7 +676,9 @@ independent of format as format specific heading characters are stripped"
         (when (string/includes? (ex-message e) "Lookup ref attribute should be marked as :db/unique: [:block/name")
           ;; old db schema
           (state/pub-event! [:notification/show
-                             {:content "It seems that the current graph is outdated, please re-index it."
+                             {:content (if (config/db-based-graph? repo)
+                                         "Unexpected error occurred."
+                                         "It seems that the current graph is outdated, please re-index it.")
                               :status :error}]))))))
 
 (defn page-empty-or-dummy?

+ 3 - 4
src/main/frontend/db/restore.cljs

@@ -1,11 +1,10 @@
 (ns frontend.db.restore
   "Fns for DB restore(from text or sqlite)"
-  (:require [clojure.string :as string]
-            [datascript.core :as d]
+  (:require [datascript.core :as d]
             [frontend.config :as config]
             [frontend.db :as db]
             [frontend.db.conn :as db-conn]
-            [frontend.db.migrate :as db-migrate]
+            [frontend.db.file-based.migrate :as db-migrate]
             [frontend.db.persist :as db-persist]
             [frontend.db.react :as react]
             [frontend.db.utils :as db-utils]
@@ -150,7 +149,7 @@
 (defn restore-graph!
   "Restore db from serialized db cache"
   [repo]
-  (if (string/starts-with? repo config/db-version-prefix)
+  (if (config/db-based-graph? repo)
     (restore-graph-from-sqlite! repo)
     (p/let [db-name (db-conn/datascript-db repo)
             stored (db-persist/get-serialized-graph db-name)]

+ 0 - 22
src/main/frontend/handler/events.cljs

@@ -661,28 +661,6 @@
                                    r))
                             (state/get-repos)))))))
 
-(defmethod handle :graph/ask-for-re-index [[_ *multiple-windows? ui]]
-  ;; *multiple-windows? - if the graph is opened in multiple windows, boolean atom
-  ;; ui - custom message to show on asking for re-index
-  (if (and (util/atom? *multiple-windows?) @*multiple-windows?)
-    (handle
-     [:modal/show
-      [:div
-       (when (not (nil? ui)) ui)
-       [:p (t :re-index-multiple-windows-warning)]]])
-    (handle
-     [:modal/show
-      [:div {:style {:max-width 700}}
-       (when (not (nil? ui)) ui)
-       [:p (t :re-index-discard-unsaved-changes-warning)]
-       (ui/button
-        (t :yes)
-        :autoFocus "on"
-        :class "ui__modal-enter"
-        :on-click (fn []
-                    (state/close-modal!)
-                    (state/pub-event! [:graph/re-index])))]])))
-
 (defmethod handle :modal/remote-encryption-input-pw-dialog [[_ repo-url remote-graph-info type opts]]
   (state/set-modal!
    (encryption/input-password

+ 24 - 1
src/main/frontend/handler/file_based/events.cljs

@@ -9,7 +9,30 @@
             [frontend.handler.web.nfs :as nfs-handler]
             [frontend.fs.sync :as sync]
             [frontend.state :as state]
-            [frontend.ui :as ui]))
+            [frontend.ui :as ui]
+            [frontend.util :as util]))
+
+(defmethod events/handle :graph/ask-for-re-index [[_ *multiple-windows? ui]]
+  ;; *multiple-windows? - if the graph is opened in multiple windows, boolean atom
+  ;; ui - custom message to show on asking for re-index
+  (if (and (util/atom? *multiple-windows?) @*multiple-windows?)
+    (events/handle
+     [:modal/show
+      [:div
+       (when (not (nil? ui)) ui)
+       [:p (t :re-index-multiple-windows-warning)]]])
+    (events/handle
+     [:modal/show
+      [:div {:style {:max-width 700}}
+       (when (not (nil? ui)) ui)
+       [:p (t :re-index-discard-unsaved-changes-warning)]
+       (ui/button
+        (t :yes)
+        :autoFocus "on"
+        :class "ui__modal-enter"
+        :on-click (fn []
+                    (state/close-modal!)
+                    (state/pub-event! [:graph/re-index])))]])))
 
 (defmethod events/handle :graph/re-index [[_]]
   ;; Ensure the graph only has ONE window instance