Browse Source

refacotr(editor): reorder create-today-journal condition, avoid file reading

Andelf 2 years ago
parent
commit
ebc8e8171f
1 changed files with 13 additions and 13 deletions
  1. 13 13
      src/main/frontend/handler/page.cljs

+ 13 - 13
src/main/frontend/handler/page.cljs

@@ -836,19 +836,19 @@
                               (config/get-file-extension format))
               repo-dir (config/get-repo-dir repo)
               template (state/get-default-journal-template)]
-          (p/let [file-exists? (fs/file-exists? repo-dir file-rpath)
-                  file-content (when file-exists?
-                                 (fs/read-file repo-dir file-rpath))]
-            (when (and (db/page-empty? repo today-page)
-                       (or (not file-exists?)
-                           (and file-exists? (string/blank? file-content))))
-              (create! title {:redirect? false
-                              :split-namespace? false
-                              :create-first-block? (not template)
-                              :journal? true})
-              (state/pub-event! [:journal/insert-template today-page])
-              (ui-handler/re-render-root!)
-              (plugin-handler/hook-plugin-app :today-journal-created {:title today-page}))))))))
+          (when (db/page-empty? repo today-page)
+            (p/let [file-exists? (fs/file-exists? repo-dir file-rpath)
+                    file-content (when file-exists?
+                                   (fs/read-file repo-dir file-rpath))]
+              (when (or (not file-exists?)
+                        (and file-exists? (string/blank? file-content)))
+                (create! title {:redirect? false
+                                :split-namespace? false
+                                :create-first-block? (not template)
+                                :journal? true})
+                (state/pub-event! [:journal/insert-template today-page])
+                (ui-handler/re-render-root!)
+                (plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))))))))
 
 (defn open-today-in-sidebar
   []