From dd95d969f183b817928d2af53b12385db80d070d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Skytte=20Randl=C3=B8v?= Date: Wed, 3 Apr 2024 11:26:25 +0200 Subject: [PATCH] feat(DiseasystoreBase): Create index on "key_" columns --- R/DiseasystoreBase.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/R/DiseasystoreBase.R b/R/DiseasystoreBase.R index f45cb64f..d5024e0f 100644 --- a/R/DiseasystoreBase.R +++ b/R/DiseasystoreBase.R @@ -221,6 +221,11 @@ DiseasystoreBase <- R6::R6Class( # Commit to DB + + # If the table does not exists, we add a index after creation + needs_index <- !SCDB::table_exists(self %.% target_conn, target_table) + + # Use update_snapshot to add the data SCDB::update_snapshot( .data = ds_updated_feature, conn = self %.% target_conn, @@ -230,6 +235,14 @@ DiseasystoreBase <- R6::R6Class( logger = logger, enforce_chronological_order = FALSE ) + + if (needs_index && packageVersion("SCDB") > "0.4.0") { + SCDB::create_index( + conn = self %.% target_conn, + db_table = target_table, + columns = purrr::keep(colnames(ds_feature), ~ stringr::str_starts(., "key_|valid_|checksum|from_ts")) + ) + } }) # Release the lock on the table