From 215ee05ef16315ffcb02e468a17773c0a0ee6280 Mon Sep 17 00:00:00 2001 From: Yves Date: Tue, 11 Mar 2025 12:44:24 +0100 Subject: [PATCH 1/3] Fix initialization order --- src/watcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/watcher.cpp b/src/watcher.cpp index 9e64b44..ef98a37 100644 --- a/src/watcher.cpp +++ b/src/watcher.cpp @@ -9,7 +9,7 @@ namespace duckdb { namespace ui { -Watcher::Watcher(HttpServer &_server) : server(_server), should_run(false) {} +Watcher::Watcher(HttpServer &_server) : should_run(false), server(_server) {} bool WasCatalogUpdated(DatabaseInstance &db, Connection &connection, CatalogState &last_state) { From 644d2d4d9eac213004ccdff3e0368b0386386d92 Mon Sep 17 00:00:00 2001 From: Yves Date: Tue, 11 Mar 2025 12:44:39 +0100 Subject: [PATCH 2/3] Simplify code --- src/http_server.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/http_server.cpp b/src/http_server.cpp index 70fd0ae..680bcc0 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -64,11 +64,7 @@ bool HttpServer::IsRunningOnMachine(ClientContext &context) { auto local_url = StringUtil::Format("http://localhost:%d", local_port); httplib::Client client(local_url); - auto result = client.Get("/info"); - if (result) { - return true; - } - return false; + return client.Get("/info"); } bool HttpServer::Started() { From f6a4077188ae4a6777423b0cc7f34380f72d4a1c Mon Sep 17 00:00:00 2001 From: Yves Date: Tue, 11 Mar 2025 12:44:49 +0100 Subject: [PATCH 3/3] Return early --- src/http_server.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/http_server.cpp b/src/http_server.cpp index 680bcc0..f43f6f5 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -40,18 +40,21 @@ void HttpServer::UpdateDatabaseInstanceIfRunning( void HttpServer::UpdateDatabaseInstance( shared_ptr context_db) { const auto current_db = server_instance->LockDatabaseInstance(); - if (current_db != context_db) { - auto watcher_stopped = false; - if (server_instance->watcher) { - server_instance->watcher->Stop(); - server_instance->watcher = nullptr; - watcher_stopped = true; - } - server_instance->ddb_instance = context_db; - if (watcher_stopped) { - server_instance->watcher = make_uniq(*this); - server_instance->watcher->Start(); - } + if (current_db == context_db) { + return; + } + + bool has_watcher = !!server_instance->watcher; + if (has_watcher) { + server_instance->watcher->Stop(); + server_instance->watcher = nullptr; + } + + server_instance->ddb_instance = context_db; + + if (has_watcher) { + server_instance->watcher = make_uniq(*this); + server_instance->watcher->Start(); } } @@ -200,6 +203,7 @@ void HttpServer::HandleGetLocalEvents(const httplib::Request &req, if (event_dispatcher->WaitEvent(&sink)) { return true; } + sink.done(); return false; });