refactor: reindex graph equals delete and re-add the same graph

pull/10933/head
Tienson Qin 2024-02-01 03:46:26 +08:00
parent 1b99388f54
commit fd306bf127
2 changed files with 27 additions and 33 deletions

View File

@ -341,14 +341,18 @@
(load-contents add-or-modify-files options)))))))
(defn remove-repo!
[{:keys [url] :as repo}]
(let [db-based? (config/db-based-graph? url)
delete-db-f (fn []
(let [current-repo (state/get-current-repo)]
[{:keys [url] :as repo} & {:keys [switch-graph?]
:or {switch-graph? true}}]
(let [current-repo (state/get-current-repo)
db-based? (config/db-based-graph? url)]
(when (or (config/local-file-based-graph? url) db-based?)
(p/do!
(idb/clear-local-db! url) ; clear file handles
(db/remove-conn! url)
(db-persist/delete-graph! url)
(search/remove-db! url)
(state/delete-repo! repo)
(when switch-graph?
(if (= current-repo url)
(when-let [graph (:url (first (state/get-repos)))]
(notification/show! (str "Removed graph "
@ -357,12 +361,7 @@
(pr-str (text-util/get-graph-name-from-path graph)))
:success)
(state/pub-event! [:graph/switch graph {:persist? false}]))
(notification/show! (str "Removed graph " (pr-str (text-util/get-graph-name-from-path url))) :success))))]
(when (or (config/local-file-based-graph? url)
db-based?
(config/demo-graph? url))
(-> (idb/clear-local-db! url) ; clear file handles
(p/finally delete-db-f)))))
(notification/show! (str "Removed graph " (pr-str (text-util/get-graph-name-from-path url))) :success)))))))
(defn start-repo-db-if-not-exists!
[repo & {:as opts}]

View File

@ -288,17 +288,12 @@
(defn rebuild-index!
[repo ok-handler]
(let [ok-handler (fn []
(ok-handler)
(state/set-nfs-refreshing! false))]
(when repo
(state/set-nfs-refreshing! true)
(search/reset-indice! repo)
(db/remove-conn! repo)
(db/clear-query-state!)
(db/start-db-conn! repo {:db-graph? (config/db-based-graph? repo)})
(reload-dir! repo {:re-index? true
:ok-handler ok-handler}))))
(let [graph-dir (config/get-repo-dir repo)]
(when (and repo (not (config/db-based-graph? repo)))
(p/do!
(repo-handler/remove-repo! {:url repo} :switch-graph? false)
(ls-dir-files-with-path! graph-dir)
(when (fn? ok-handler) (ok-handler))))))
;; TODO: move to frontend.handler.repo
(defn refresh!