diff --git a/apps/labrinth/src/clickhouse/mod.rs b/apps/labrinth/src/clickhouse/mod.rs index e7c2215f..8bc00921 100644 --- a/apps/labrinth/src/clickhouse/mod.rs +++ b/apps/labrinth/src/clickhouse/mod.rs @@ -48,6 +48,13 @@ pub async fn init_client_with_database( "MergeTree()" }; + // For the Clickhouse database on the staging environment, set a TTL to avoid accumulating too much data + let ttl = if database == "staging_analytics" { + "TTL toDateTime(recorded) + INTERVAL 1 DAY" + } else { + "" + }; + client .query(&format!( " @@ -67,6 +74,7 @@ pub async fn init_client_with_database( headers Array(Tuple(String, String)) ) ENGINE = {engine} + {ttl} PRIMARY KEY (project_id, recorded, ip) SETTINGS index_granularity = 8192 " @@ -93,6 +101,7 @@ pub async fn init_client_with_database( headers Array(Tuple(String, String)) ) ENGINE = {engine} + {ttl} PRIMARY KEY (project_id, recorded, ip) SETTINGS index_granularity = 8192 " @@ -117,6 +126,7 @@ pub async fn init_client_with_database( parent UInt64 ) ENGINE = {engine} + {ttl} PRIMARY KEY (project_id, recorded, user_id) SETTINGS index_granularity = 8192 "