refactor: remove dead code (#3337)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-09 01:41:26 +02:00
1 parent a19002652b
commit 93d1f8af46
1527 files changed
+21170 -73846

No files matched your search

-45
View File
@@ -1,45 +0,0 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
use moka::future::Cache;
use std::future::Future;
use std::sync::Arc;
use std::time::Duration;
pub struct L1Cache<V> {
cache: Cache<String, V>,
}
impl<V: Clone + Send + Sync + 'static> L1Cache<V> {
pub fn new(max_entries: u64, ttl: Duration) -> Self {
Self {
cache: Cache::builder()
.max_capacity(max_entries)
.time_to_live(ttl)
.build(),
}
}
pub async fn get(&self, key: &str) -> Option<V> {
self.cache.get(key).await
}
pub async fn insert(&self, key: &str, value: V) {
self.cache.insert(key.to_owned(), value).await;
}
pub async fn invalidate(&self, key: &str) {
self.cache.invalidate(key).await;
}
pub async fn get_or_try_insert_with<F, E>(&self, key: String, init: F) -> Result<V, Arc<E>>
where
F: Future<Output = Result<V, E>> + Send + 'static,
E: Send + Sync + 'static,
{
self.cache.try_get_with(key, init).await
}
pub fn entry_count(&self) -> u64 {
self.cache.entry_count()
}
}
-1
View File
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pub mod cache;
pub mod config;
pub mod hash_ring;
pub mod metrics;
+11 -53
View File
@@ -361,7 +361,6 @@ pub struct KvClient {
get_row_sql: String,
get_rows_sql: String,
get_partition_rows_sql: String,
get_row_key_prefix_rows_sql: String,
delete_row_sql: String,
}
@@ -380,9 +379,6 @@ impl KvClient {
get_partition_rows_sql: format!(
"SELECT row_key, row_data FROM {table} WHERE table_name = $1 AND partition_key = $2 AND (expires_at IS NULL OR expires_at > now())"
),
get_row_key_prefix_rows_sql: format!(
"SELECT row_key, row_data FROM {table} WHERE table_name = $1 AND row_key COLLATE \"C\" >= $2 AND row_key COLLATE \"C\" < $3 AND (expires_at IS NULL OR expires_at > now())"
),
delete_row_sql: format!("DELETE FROM {table} WHERE table_name = $1 AND row_key = $2"),
})
}
@@ -495,27 +491,6 @@ impl KvClient {
Ok(rows.into_iter().map(row_key_and_data).collect())
}
pub async fn get_row_key_prefix_rows(
&self,
table_name: &str,
row_key_prefix: &str,
) -> anyhow::Result<Vec<(String, Value)>> {
let client = self.pool.get().await?;
let upper = format!("{row_key_prefix}\u{10ffff}");
let rows = self
.query_rows(
&client,
&self.get_row_key_prefix_rows_sql,
&[
(&table_name, Type::TEXT),
(&row_key_prefix, Type::TEXT),
(&upper, Type::TEXT),
],
)
.await?;
Ok(rows.into_iter().map(row_key_and_data).collect())
}
pub async fn get_partition_rows_by_bigint_field(
&self,
table_name: &str,
@@ -686,18 +661,8 @@ pub fn kv_key(parts: &[KeyPart<'_>]) -> anyhow::Result<String> {
.map(|parts| parts.join("\u{001f}"))
}
pub fn decode_row(value: Value) -> anyhow::Result<Value> {
decode_value(value, DecodeDateMode::String)
}
pub fn decode_row_dates_as_millis(value: Value) -> anyhow::Result<Value> {
decode_value(value, DecodeDateMode::Millis)
}
#[derive(Clone, Copy)]
enum DecodeDateMode {
String,
Millis,
decode_value(value)
}
fn encoded_key_part(part: &KeyPart<'_>) -> anyhow::Result<String> {
@@ -718,11 +683,11 @@ fn encoded_key_part(part: &KeyPart<'_>) -> anyhow::Result<String> {
Ok(serde_json::to_string(&value)?)
}
fn decode_value(value: Value, date_mode: DecodeDateMode) -> anyhow::Result<Value> {
fn decode_value(value: Value) -> anyhow::Result<Value> {
match value {
Value::Array(values) => values
.into_iter()
.map(|value| decode_value(value, date_mode))
.map(decode_value)
.collect::<anyhow::Result<Vec<_>>>()
.map(Value::Array),
Value::Object(mut object) => match object.get("__fluxer_type").and_then(Value::as_str) {
@@ -742,20 +707,17 @@ fn decode_value(value: Value, date_mode: DecodeDateMode) -> anyhow::Result<Value
.remove("value")
.and_then(|value| value.as_str().map(ToOwned::to_owned))
.unwrap_or_default();
match date_mode {
DecodeDateMode::String => Ok(Value::String(value)),
DecodeDateMode::Millis => Ok(DateTime::parse_from_rfc3339(&value)
.map(|dt| {
Value::Number(Number::from(dt.with_timezone(&Utc).timestamp_millis()))
})
.unwrap_or(Value::String(value))),
}
Ok(DateTime::parse_from_rfc3339(&value)
.map(|dt| {
Value::Number(Number::from(dt.with_timezone(&Utc).timestamp_millis()))
})
.unwrap_or(Value::String(value)))
}
Some("buffer" | "local_date") => Ok(object.remove("value").unwrap_or(Value::Null)),
Some("set") => match object.remove("value").unwrap_or(Value::Null) {
Value::Array(values) => values
.into_iter()
.map(|value| decode_value(value, date_mode))
.map(decode_value)
.collect::<anyhow::Result<Vec<_>>>()
.map(Value::Array),
_ => Ok(Value::Array(Vec::new())),
@@ -763,14 +725,14 @@ fn decode_value(value: Value, date_mode: DecodeDateMode) -> anyhow::Result<Value
Some("map") => match object.remove("value").unwrap_or(Value::Null) {
Value::Array(entries) => entries
.into_iter()
.map(|entry| decode_value(entry, date_mode))
.map(decode_value)
.collect::<anyhow::Result<Vec<_>>>()
.map(Value::Array),
_ => Ok(Value::Array(Vec::new())),
},
_ => object
.into_iter()
.map(|(key, value)| decode_value(value, date_mode).map(|value| (key, value)))
.map(|(key, value)| decode_value(value).map(|value| (key, value)))
.collect::<anyhow::Result<Map<_, _>>>()
.map(Value::Object),
},
@@ -889,10 +851,6 @@ mod tests {
kv.get_partition_rows_sql,
"SELECT row_key, row_data FROM \"fluxer_kv\" WHERE table_name = $1 AND partition_key = $2 AND (expires_at IS NULL OR expires_at > now())"
);
assert_eq!(
kv.get_row_key_prefix_rows_sql,
"SELECT row_key, row_data FROM \"fluxer_kv\" WHERE table_name = $1 AND row_key COLLATE \"C\" >= $2 AND row_key COLLATE \"C\" < $3 AND (expires_at IS NULL OR expires_at > now())"
);
assert_eq!(
kv.delete_row_sql,
"DELETE FROM \"fluxer_kv\" WHERE table_name = $1 AND row_key = $2"