Skip to content

Commit

Permalink
fix: a bug cause page content cache outdate when external edition hap…
Browse files Browse the repository at this point in the history
…pens
  • Loading branch information
cnrpman committed Jan 11, 2023
1 parent 05ff96e commit 6785486
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/electron/electron/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
[repo pages]
(if-let [db (get-db repo)]
;; TODO: what if a CONFLICT on uuid
(let [insert (prepare db "INSERT INTO pages (id, uuid, content) VALUES (@id, @uuid, @content) ON CONFLICT (id) DO UPDATE SET content = @content")
;; Should update all values on id conflict
(let [insert (prepare db "INSERT INTO pages (id, uuid, content) VALUES (@id, @uuid, @content) ON CONFLICT (id) DO UPDATE SET (uuid, content) = (@uuid, @content)")
insert-many (.transaction ^object db
(fn [pages]
(doseq [page pages]
Expand All @@ -190,7 +191,8 @@
[repo blocks]
(if-let [db (get-db repo)]
;; TODO: what if a CONFLICT on uuid
(let [insert (prepare db "INSERT INTO blocks (id, uuid, content, page) VALUES (@id, @uuid, @content, @page) ON CONFLICT (id) DO UPDATE SET content = @content")
;; Should update all values on id conflict
(let [insert (prepare db "INSERT INTO blocks (id, uuid, content, page) VALUES (@id, @uuid, @content, @page) ON CONFLICT (id) DO UPDATE SET (uuid, content, page) = (@uuid, @content, @page)")
insert-many (.transaction ^object db
(fn [blocks]
(doseq [block blocks]
Expand Down
2 changes: 2 additions & 0 deletions src/main/frontend/components/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@
nil)]))

(rum/defc search-auto-complete
"has-more? - if the result is truncated
all? - if true, in show-more mode"
[{:keys [engine pages files pages-content blocks has-more?] :as result} search-q all?]
(let [pages (when-not all? (map (fn [page]
(let [alias (model/get-redirect-page-name page)]
Expand Down
1 change: 1 addition & 0 deletions src/main/frontend/handler/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
(text/remove-level-spaces content format (config/get-block-pattern format)))

(defn search
"The aggretation of search results"
([q]
(search (state/get-current-repo) q))
([repo q]
Expand Down
3 changes: 3 additions & 0 deletions src/main/frontend/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
(protocol/transact-blocks! engine data)))

(defn- transact-pages!
"Transact pages to search engine
:pages-to-remove-set the set of pages to remove (not include those to update)
:pages-to-add the page entities to add"
[repo data]
(when-let [engine (get-engine repo)]
(protocol/transact-pages! engine data)))
Expand Down

0 comments on commit 6785486

Please sign in to comment.