Terminate watcher if database changes (#20)

* Terminate watcher if database changes

* Format

* Update watcher.cpp

* Revert "Format"

This reverts commit 72d82f4bce.
This commit is contained in:
Y.
2025-08-15 00:47:15 +02:00
committed by GitHub
parent 8a724108f1
commit 96dfa0d32b
2 changed files with 9 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ private:
std::condition_variable cv;
std::atomic<bool> should_run;
HttpServer &server;
DatabaseInstance *watched_database;
};
} // namespace ui
} // namespace duckdb

View File

@@ -9,7 +9,8 @@
namespace duckdb {
namespace ui {
Watcher::Watcher(HttpServer &_server) : should_run(false), server(_server) {}
Watcher::Watcher(HttpServer &_server)
: should_run(false), server(_server), watched_database(nullptr) {}
bool WasCatalogUpdated(DatabaseInstance &db, Connection &connection,
CatalogState &last_state) {
@@ -62,6 +63,12 @@ void Watcher::Watch() {
break; // DB went away, nothing to watch
}
if (watched_database == nullptr) {
watched_database = db.get();
} else if (watched_database != db.get()) {
break; // DB changed, stop watching, will be restarted
}
duckdb::Connection con{*db};
auto polling_interval = GetPollingInterval(*con.context);
if (polling_interval == 0) {