Return early

This commit is contained in:
Yves
2025-03-11 12:44:49 +01:00
parent 644d2d4d9e
commit f6a4077188

View File

@@ -40,20 +40,23 @@ void HttpServer::UpdateDatabaseInstanceIfRunning(
void HttpServer::UpdateDatabaseInstance( void HttpServer::UpdateDatabaseInstance(
shared_ptr<DatabaseInstance> context_db) { shared_ptr<DatabaseInstance> context_db) {
const auto current_db = server_instance->LockDatabaseInstance(); const auto current_db = server_instance->LockDatabaseInstance();
if (current_db != context_db) { if (current_db == context_db) {
auto watcher_stopped = false; return;
if (server_instance->watcher) { }
bool has_watcher = !!server_instance->watcher;
if (has_watcher) {
server_instance->watcher->Stop(); server_instance->watcher->Stop();
server_instance->watcher = nullptr; server_instance->watcher = nullptr;
watcher_stopped = true;
} }
server_instance->ddb_instance = context_db; server_instance->ddb_instance = context_db;
if (watcher_stopped) {
if (has_watcher) {
server_instance->watcher = make_uniq<Watcher>(*this); server_instance->watcher = make_uniq<Watcher>(*this);
server_instance->watcher->Start(); server_instance->watcher->Start();
} }
} }
}
bool HttpServer::IsRunningOnMachine(ClientContext &context) { bool HttpServer::IsRunningOnMachine(ClientContext &context) {
if (Started()) { if (Started()) {
@@ -200,6 +203,7 @@ void HttpServer::HandleGetLocalEvents(const httplib::Request &req,
if (event_dispatcher->WaitEvent(&sink)) { if (event_dispatcher->WaitEvent(&sink)) {
return true; return true;
} }
sink.done(); sink.done();
return false; return false;
}); });