perf(dashboard): live event object picker without a correlated EXISTS

The picker's EXISTS on ComponentsRegistry (no index) took 2 to 4 s with the bundled SQLite for the
treasure kinds; the same filter as IN takes under 10 ms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-26 18:45:39 -05:00
parent 99aecc6b74
commit 91c9f4a13d

View File

@@ -420,9 +420,11 @@ namespace LiveEventRoutes {
const auto& types = ObjectTypes(kind);
std::string placeholders;
for (size_t i = 0; i < types.size(); i++) placeholders += i ? ", ?" : "?";
// IN, not a correlated EXISTS: ComponentsRegistry has no index, and the EXISTS form took seconds with the
// bundled SQLite for the kinds with thousands of objects
auto stmt = CDClientDatabase::CreatePreppedStmt(
"SELECT o.id, o.name, o.displayName, o.type FROM Objects o WHERE o.type IN (" + placeholders + ") "
"AND EXISTS (SELECT 1 FROM ComponentsRegistry c WHERE c.id = o.id AND c.component_type = ?) "
"AND o.id IN (SELECT c.id FROM ComponentsRegistry c WHERE c.component_type = ?) "
"AND (? = '' OR o.name LIKE '%' || ? || '%' OR o.displayName LIKE '%' || ? || '%' OR o.id = ?) ORDER BY o.name LIMIT 60;");
int index = 1;
for (const auto& type : types) stmt.bind(index++, type.c_str());