From bacffd617427d835d0792b87ef64cba8aad95bae Mon Sep 17 00:00:00 2001
From: strawberry <strawberry@puppygock.gay>
Date: Sat, 13 Jul 2024 16:46:13 -0400
Subject: [PATCH] rename `conduit_cache_capacity_modifier` to
 `cache_capacity_modifier`

this prefix causes you to require setting the environment variable
to `CONDUWUIT_CONDUIT_CACHE_CAPACITY_MODIFIER`

alias this so we dont break any configs

Signed-off-by: strawberry <strawberry@puppygock.gay>
---
 conduwuit-example.toml                    |  5 ++++-
 src/core/config/mod.rs                    | 11 ++++++-----
 src/database/opts.rs                      |  2 +-
 src/service/rooms/auth_chain/data.rs      |  2 +-
 src/service/rooms/spaces/mod.rs           |  2 +-
 src/service/rooms/state_accessor/mod.rs   |  4 ++--
 src/service/rooms/state_compressor/mod.rs |  2 +-
 7 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/conduwuit-example.toml b/conduwuit-example.toml
index ea095bfa1..570931281 100644
--- a/conduwuit-example.toml
+++ b/conduwuit-example.toml
@@ -421,8 +421,11 @@ allow_profile_lookup_federation_requests = true
 
 # Set this to any float value to multiply conduwuit's in-memory LRU caches with.
 # May be useful if you have significant memory to spare to increase performance.
+#
+# This was previously called `conduit_cache_capacity_modifier`
+#
 # Defaults to 1.0.
-#conduit_cache_capacity_modifier = 1.0
+#cache_capacity_modifier = 1.0
 
 # Set this to any float value in megabytes for conduwuit to tell the database engine that this much memory is available for database-related caches.
 # May be useful if you have significant memory to spare to increase performance.
diff --git a/src/core/config/mod.rs b/src/core/config/mod.rs
index 336144db5..b40ebb65f 100644
--- a/src/core/config/mod.rs
+++ b/src/core/config/mod.rs
@@ -58,8 +58,8 @@ pub struct Config {
 
 	#[serde(default = "default_pdu_cache_capacity")]
 	pub pdu_cache_capacity: u32,
-	#[serde(default = "default_conduit_cache_capacity_modifier")]
-	pub conduit_cache_capacity_modifier: f64,
+	#[serde(default = "default_cache_capacity_modifier", alias = "conduit_cache_capacity_modifier")]
+	pub cache_capacity_modifier: f64,
 	#[serde(default = "default_auth_chain_cache_capacity")]
 	pub auth_chain_cache_capacity: u32,
 	#[serde(default = "default_shorteventid_cache_capacity")]
@@ -391,8 +391,9 @@ struct ListeningAddr {
 	addrs: Either<IpAddr, Vec<IpAddr>>,
 }
 
-const DEPRECATED_KEYS: &[&str] = &[
+const DEPRECATED_KEYS: &[&str; 9] = &[
 	"cache_capacity",
+	"conduit_cache_capacity_modifier",
 	"max_concurrent_requests",
 	"well_known_client",
 	"well_known_server",
@@ -484,7 +485,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 		);
 		line("Database backups to keep", &self.database_backups_to_keep.to_string());
 		line("Database cache capacity (MB)", &self.db_cache_capacity_mb.to_string());
-		line("Cache capacity modifier", &self.conduit_cache_capacity_modifier.to_string());
+		line("Cache capacity modifier", &self.cache_capacity_modifier.to_string());
 		line("PDU cache capacity", &self.pdu_cache_capacity.to_string());
 		line("Auth chain cache capacity", &self.auth_chain_cache_capacity.to_string());
 		line("Short eventid cache capacity", &self.shorteventid_cache_capacity.to_string());
@@ -847,7 +848,7 @@ fn default_db_cache_capacity_mb() -> f64 { 256.0 }
 
 fn default_pdu_cache_capacity() -> u32 { 150_000 }
 
-fn default_conduit_cache_capacity_modifier() -> f64 { 1.0 }
+fn default_cache_capacity_modifier() -> f64 { 1.0 }
 
 fn default_auth_chain_cache_capacity() -> u32 { 100_000 }
 
diff --git a/src/database/opts.rs b/src/database/opts.rs
index 1b9c163fb..d22364548 100644
--- a/src/database/opts.rs
+++ b/src/database/opts.rs
@@ -310,7 +310,7 @@ fn set_table_with_shared_cache(
 }
 
 fn cache_size(config: &Config, base_size: u32, entity_size: usize) -> usize {
-	let ents = f64::from(base_size) * config.conduit_cache_capacity_modifier;
+	let ents = f64::from(base_size) * config.cache_capacity_modifier;
 
 	#[allow(clippy::as_conversions, clippy::cast_sign_loss, clippy::cast_possible_truncation)]
 	(ents as usize)
diff --git a/src/service/rooms/auth_chain/data.rs b/src/service/rooms/auth_chain/data.rs
index 5efb36c2a..4e4682343 100644
--- a/src/service/rooms/auth_chain/data.rs
+++ b/src/service/rooms/auth_chain/data.rs
@@ -16,7 +16,7 @@ impl Data {
 	pub(super) fn new(server: &Arc<Server>, db: &Arc<Database>) -> Self {
 		let config = &server.config;
 		let cache_size = f64::from(config.auth_chain_cache_capacity);
-		let cache_size = usize_from_f64(cache_size * config.conduit_cache_capacity_modifier).expect("valid cache size");
+		let cache_size = usize_from_f64(cache_size * config.cache_capacity_modifier).expect("valid cache size");
 		Self {
 			shorteventid_authchain: db["shorteventid_authchain"].clone(),
 			auth_chain_cache: Mutex::new(LruCache::new(cache_size)),
diff --git a/src/service/rooms/spaces/mod.rs b/src/service/rooms/spaces/mod.rs
index 18133fc1f..02db7fab1 100644
--- a/src/service/rooms/spaces/mod.rs
+++ b/src/service/rooms/spaces/mod.rs
@@ -161,7 +161,7 @@ impl crate::Service for Service {
 	fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
 		let config = &args.server.config;
 		let cache_size = f64::from(config.roomid_spacehierarchy_cache_capacity);
-		let cache_size = cache_size * config.conduit_cache_capacity_modifier;
+		let cache_size = cache_size * config.cache_capacity_modifier;
 		Ok(Arc::new(Self {
 			roomid_spacehierarchy_cache: Mutex::new(LruCache::new(usize_from_f64(cache_size)?)),
 		}))
diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs
index 7abe5e0fc..bd3eb0a15 100644
--- a/src/service/rooms/state_accessor/mod.rs
+++ b/src/service/rooms/state_accessor/mod.rs
@@ -45,9 +45,9 @@ impl crate::Service for Service {
 	fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
 		let config = &args.server.config;
 		let server_visibility_cache_capacity =
-			f64::from(config.server_visibility_cache_capacity) * config.conduit_cache_capacity_modifier;
+			f64::from(config.server_visibility_cache_capacity) * config.cache_capacity_modifier;
 		let user_visibility_cache_capacity =
-			f64::from(config.user_visibility_cache_capacity) * config.conduit_cache_capacity_modifier;
+			f64::from(config.user_visibility_cache_capacity) * config.cache_capacity_modifier;
 
 		Ok(Arc::new(Self {
 			db: Data::new(args.db),
diff --git a/src/service/rooms/state_compressor/mod.rs b/src/service/rooms/state_compressor/mod.rs
index 4b4ea7d4e..422c562b8 100644
--- a/src/service/rooms/state_compressor/mod.rs
+++ b/src/service/rooms/state_compressor/mod.rs
@@ -55,7 +55,7 @@ pub struct Service {
 impl crate::Service for Service {
 	fn build(args: crate::Args<'_>) -> Result<Arc<Self>> {
 		let config = &args.server.config;
-		let cache_capacity = f64::from(config.stateinfo_cache_capacity) * config.conduit_cache_capacity_modifier;
+		let cache_capacity = f64::from(config.stateinfo_cache_capacity) * config.cache_capacity_modifier;
 		Ok(Arc::new(Self {
 			db: Data::new(args.db),
 			stateinfo_cache: StdMutex::new(LruCache::new(usize_from_f64(cache_capacity)?)),
-- 
GitLab