Skip to content

FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.

perf: add DB indexes for instruments(broker_id) and news_articles(sort_ts)

tilakpatel22e16e4665859f
diff --git a/fincept-qt/CMakeLists.txt b/fincept-qt/CMakeLists.txt
index e6fda9880..38866b07c 100644
--- a/fincept-qt/CMakeLists.txt
+++ b/fincept-qt/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
-project(FinceptTerminal VERSION 4.0.0 LANGUAGES CXX)
+project(FinceptTerminal VERSION 4.0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -375,6 +375,7 @@ set(STORAGE_SOURCES
# Multi-account broker support
src/storage/sqlite/migrations/v016_broker_accounts.cpp
+ src/storage/sqlite/migrations/v017_perf_indexes.cpp
)
# Python runner
@@ -1146,6 +1147,7 @@ set_source_files_properties(
src/storage/sqlite/migrations/v014_llm_tools_toggle.cpp
src/storage/sqlite/migrations/v015_screen_state.cpp
src/storage/sqlite/migrations/v016_broker_accounts.cpp
+ src/storage/sqlite/migrations/v017_perf_indexes.cpp
# Polymarket screen files — each defines static fmt_* helpers in same namespace
src/screens/polymarket/PolymarketScreen.cpp
src/screens/polymarket/PolymarketCommandBar.cpp
diff --git a/fincept-qt/src/app/main.cpp b/fincept-qt/src/app/main.cpp
index d33ef19e6..78374b650 100644
--- a/fincept-qt/src/app/main.cpp
+++ b/fincept-qt/src/app/main.cpp
@@ -70,7 +70,7 @@ int main(int argc, char* argv[]) {
profile_key.toUtf8());
app.setApplicationName("FinceptTerminal");
app.setOrganizationName("Fincept");
- app.setApplicationVersion("4.0.0");
+ app.setApplicationVersion("4.0.1");
// ── Secondary instance: signal primary to open a new window, then exit ───
// The primary receives receivedMessage() and calls open_new_window().
@@ -157,7 +157,7 @@ int main(int argc, char* argv[]) {
log.set_tag_level(tag, lvl_map.value(level));
}
}
- LOG_INFO("App", "Fincept Terminal v4.0.0 starting...");
+ LOG_INFO("App", "Fincept Terminal v4.0.1 starting...");
// Theme is applied after DB is open so saved font/theme are respected from the start.
@@ -184,6 +184,7 @@ int main(int argc, char* argv[]) {
fincept::register_migration_v014();
fincept::register_migration_v015();
fincept::register_migration_v016();
+ fincept::register_migration_v017();
// Open main database
QString db_path = fincept::AppPaths::data() + "/fincept.db";
diff --git a/fincept-qt/src/storage/sqlite/migrations/MigrationRunner.h b/fincept-qt/src/storage/sqlite/migrations/MigrationRunner.h
index 8d4fbb728..ad5c7fa19 100644
--- a/fincept-qt/src/storage/sqlite/migrations/MigrationRunner.h
+++ b/fincept-qt/src/storage/sqlite/migrations/MigrationRunner.h
@@ -63,5 +63,6 @@ void register_migration_v013();
void register_migration_v014();
void register_migration_v015();
void register_migration_v016();
+void register_migration_v017();
} // namespace fincept
diff --git a/fincept-qt/src/storage/sqlite/migrations/v017_perf_indexes.cpp b/fincept-qt/src/storage/sqlite/migrations/v017_perf_indexes.cpp
new file mode 100644
index 000000000..8969a1103
--- /dev/null
+++ b/fincept-qt/src/storage/sqlite/migrations/v017_perf_indexes.cpp
@@ -0,0 +1,47 @@
+// v017_perf_indexes — Add performance indexes for startup-critical queries.
+//
+// 1. idx_inst_broker on instruments(broker_id) — needed by load_from_db_async
+// single-broker SELECT (replacing 9 per-exchange queries).
+// 2. idx_news_sort_ts on news_articles(sort_ts) — already on sort_ts per
+// prune_older_than query; CREATE IF NOT EXISTS is safe if it already exists.
+
+#include "storage/sqlite/migrations/MigrationRunner.h"
+
+#include <QSqlError>
+#include <QSqlQuery>
+
+namespace fincept {
+namespace {
+
+Result<void> sql(QSqlDatabase& db, const char* stmt) {
+ QSqlQuery q(db);
+ if (!q.exec(stmt))
+ return Result<void>::err(q.lastError().text().toStdString());
+ return Result<void>::ok();
+}
+
+Result<void> apply_v017(QSqlDatabase& db) {
+ auto r = sql(db, "CREATE INDEX IF NOT EXISTS idx_inst_broker "
+ "ON instruments(broker_id)");
+ if (r.is_err())
+ return r;
+
+ r = sql(db, "CREATE INDEX IF NOT EXISTS idx_news_sort_ts "
+ "ON news_articles(sort_ts)");
+ if (r.is_err())
+ return r;
+
+ return Result<void>::ok();
+}
+
+} // anonymous namespace
+
+void register_migration_v017() {
+ static bool done = false;
+ if (done)
+ return;
+ done = true;
+ MigrationRunner::register_migration({17, "perf_indexes", apply_v017});
+}
+
+} // namespace fincept