فهرست منبع

fix: search failed because of wrong timestamp format

Tienson Qin 4 سال پیش
والد
کامیت
1c53d8f316
4فایلهای تغییر یافته به همراه16 افزوده شده و 20 حذف شده
  1. 7 7
      src/main/frontend/db/model.cljs
  2. 4 1
      src/main/frontend/fs.cljs
  3. 2 2
      src/main/frontend/fs/watcher_handler.cljs
  4. 3 10
      src/main/frontend/handler/page.cljs

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

@@ -82,12 +82,12 @@
 
 (defn get-modified-pages
   [repo]
-  (d/q
-   '[:find ?page-name ?modified-at
-     :where
-     [?page :page/original-name ?page-name]
-     [(get-else $ ?page :page/last-modified-at 0) ?modified-at]]
-   (conn/get-conn repo)))
+  (-> (d/q
+       '[:find ?page-name
+         :where
+         [?page :page/original-name ?page-name]]
+       (conn/get-conn repo))
+      (db-utils/seq-flatten)))
 
 (defn get-page-alias
   [repo page-name]
@@ -130,7 +130,7 @@
           '[:find ?path ?modified-at
             :where
             [?file :file/path ?path]
-            [(get-else $ ?file :file/last-modified-at 0) ?modified-at]]
+            [?file :file/last-modified-at ?modified-at]]
           conn)
          (seq)
          (sort-by last)

+ 4 - 1
src/main/frontend/fs.cljs

@@ -8,6 +8,7 @@
             [frontend.fs.nfs :as nfs]
             [frontend.fs.bfs :as bfs]
             [frontend.fs.node :as node]
+            [frontend.db :as db]
             [cljs-bean.core :as bean]
             [frontend.state :as state]))
 
@@ -62,7 +63,9 @@
 (defn write-file!
   [repo dir path content opts]
   (->
-   (protocol/write-file! (get-fs dir) repo dir path content opts)
+   (do
+     (protocol/write-file! (get-fs dir) repo dir path content opts)
+     (db/set-file-last-modified-at! repo path (js/Date.)))
    (p/catch (fn [error]
               (log/error :file/write-failed? {:dir dir
                                               :path path

+ 2 - 2
src/main/frontend/fs/watcher_handler.cljs

@@ -16,8 +16,7 @@
   [type {:keys [dir path content stat] :as payload}]
   (when dir
     (let [repo (config/get-local-repo dir)
-          {:keys [mtime]} stat
-          mtime (tc/to-long mtime)]
+          {:keys [mtime]} stat]
       (cond
         (= "add" type)
         (let [db-content (db/get-file path)]
@@ -39,6 +38,7 @@
              (not= content (db/get-file path))
              (when-let [last-modified-at (db/get-file-last-modified-at repo path)]
                (> mtime last-modified-at)))
+
         (file-handler/alter-file repo path content {:re-render-root? true})
 
         (= "unlink" type)

+ 3 - 10
src/main/frontend/handler/page.cljs

@@ -496,18 +496,11 @@
         (let [templates (map string/lower-case templates)]
           (contains? (set templates) (string/lower-case title)))))))
 
+;; TODO: add use :file/last-modified-at
 (defn get-pages-with-modified-at
   [repo]
-  (let [now-long (tc/to-long (t/now))]
-    (->> (db/get-modified-pages repo)
-         (seq)
-         (sort-by (fn [[page modified-at]]
-                    [modified-at page]))
-         (reverse)
-         (remove (fn [[page modified-at]]
-                   (or (util/file-page? page)
-                       (and modified-at
-                            (> modified-at now-long))))))))
+  (->> (db/get-modified-pages repo)
+       (remove util/file-page?)))
 
 (defn page-exists?
   [page-name]