Skip to content

Commit

Permalink
feat(search): delete the search db when unlink a graph
Browse files Browse the repository at this point in the history
  • Loading branch information
tiensonqin committed Apr 8, 2021
1 parent 5526ee4 commit d28b728
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/electron/electron/handler.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
(defmethod handle :truncate-blocks [window [_ repo]]
(search/truncate-blocks-table! repo))

(defmethod handle :remove-db [window [_ repo]]
(search/delete-db! repo))

(defn- get-file-ext
[file]
(last (string/split file #"\.")))
Expand Down
24 changes: 18 additions & 6 deletions src/electron/electron/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
(defn close!
[]
(when @databases
(doseq [database @databases]
(.close databases))
(doseq [[_ database] @databases]
(.close database))
(reset! databases nil)))

(defn normalize-db-name
Expand Down Expand Up @@ -78,11 +78,15 @@
[]
(fs/ensureDirSync (get-search-dir)))

(defn open-db!
(defn get-db-full-path
[db-name]
(let [db-name (normalize-db-name db-name)
search-dir (get-search-dir)
db-full-path (path/join search-dir db-name)
search-dir (get-search-dir)]
[db-name (path/join search-dir db-name)]))

(defn open-db!
[db-name]
(let [[db-name db-full-path] (get-db-full-path db-name)
db (sqlite3 db-full-path nil)
_ (create-blocks-table! db)]
(swap! databases assoc db-name db)))
Expand Down Expand Up @@ -150,7 +154,15 @@
;; "drop table blocks_fts;")
]
;; (.run ^object stmt)
)))
)))

(defn delete-db!
[repo]
(when-let [database (get-db repo)]
(.close database)
(let [[_ db-full-path] (get-db-full-path repo)]
(println "Delete search indice: " db-full-path)
(fs/unlinkSync db-full-path))))


(comment
Expand Down
1 change: 1 addition & 0 deletions src/main/frontend/handler/repo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@
(db/remove-conn! url)
(db/remove-db! url)
(db/remove-files-db! url)
(search/remove-db! url)
(fs/rmdir! (config/get-repo-dir url))
(state/delete-repo! repo))]
(if (config/local-db? url)
Expand Down
5 changes: 5 additions & 0 deletions src/main/frontend/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,8 @@
(when-let [engine (get-engine repo)]
(protocol/truncate-blocks! engine))
(swap! indices assoc-in [repo :pages] nil))

(defn remove-db!
[repo]
(when-let [engine (get-engine repo)]
(protocol/remove-db! engine)))
4 changes: 3 additions & 1 deletion src/main/frontend/search/browser.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@
(.add indice (bean/->js block)))))
indice)))
(truncate-blocks! [this]
(swap! indices assoc-in [repo :blocks] nil)))
(swap! indices assoc-in [repo :blocks] nil))
(remove-db! [this]
nil))
4 changes: 3 additions & 1 deletion src/main/frontend/search/node.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@
(transact-blocks! [this data]
(ipc/ipc "transact-blocks" repo (bean/->js data)))
(truncate-blocks! [this]
(ipc/ipc "truncate-blocks" repo)))
(ipc/ipc "truncate-blocks" repo))
(remove-db! [this]
(ipc/ipc "remove-db" repo)))
3 changes: 2 additions & 1 deletion src/main/frontend/search/protocol.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
(query [this q option])
(rebuild-blocks-indice! [this])
(transact-blocks! [this data])
(truncate-blocks! [this]))
(truncate-blocks! [this])
(remove-db! [this]))

0 comments on commit d28b728

Please sign in to comment.