فهرست منبع

enhance: only restore the last opened graph

Tienson Qin 3 سال پیش
والد
کامیت
c37b5bd622
2فایلهای تغییر یافته به همراه10 افزوده شده و 13 حذف شده
  1. 5 7
      src/main/frontend/db.cljs
  2. 5 6
      src/main/frontend/handler.cljs

+ 5 - 7
src/main/frontend/db.cljs

@@ -183,16 +183,14 @@
                 (d/transact! db-conn [(me-tx (d/db db-conn) me)])))]
     (d/transact! db-conn [{:schema/version db-schema/version}])))
 
-;; TODO: only restore the current graph instead of all the graphs to speedup and
 ;; reduce memory usage. pub event :graph/ready when a graph is restored, and finish the TODOs in :graph/ready
 (defn restore!
   [{:keys [repos] :as me} _old-db-schema restore-config-handler]
-  (doall
-   (for [{:keys [url]} repos]
-     (let [repo url]
-       (p/let [_ (restore-graph! repo me)]
-         (restore-config-handler repo)
-         (listen-and-persist! repo))))))
+  (let [repo (or (state/get-current-repo) (:url (first repos)))]
+    (when repo
+      (p/let [_ (restore-graph! repo me)]
+        (restore-config-handler repo)
+        (listen-and-persist! repo)))))
 
 (defn run-batch-txs!
   []

+ 5 - 6
src/main/frontend/handler.cljs

@@ -90,12 +90,11 @@
                    (when (and @interval js/window.pfs)
                      (js/clearInterval @interval)
                      (reset! interval nil)
-                     ;; `(state/set-db-restoring! true)` already executed before restoring
-                     (-> (p/all (db/restore!
-                                 (assoc me :repos repos)
-                                 old-db-schema
-                                 (fn [repo]
-                                   (file-handler/restore-config! repo false))))
+                     (-> (db/restore!
+                          (assoc me :repos repos)
+                          old-db-schema
+                          (fn [repo]
+                            (file-handler/restore-config! repo false)))
                          (p/then
                           (fn []
                             ;; try to load custom css only for current repo