Skip to content

Commit

Permalink
use typed-builder in kitsune-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Oct 18, 2023
1 parent 7e34f28 commit bffcff1
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 137 deletions.
206 changes: 107 additions & 99 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
[profile.dev.package.backtrace]
opt-level = 3

[profile.dev.package.num-bigint-dig]
opt-level = 3

[profile.release]
codegen-units = 1
Expand Down Expand Up @@ -42,3 +37,4 @@ version = "0.0.1-pre.3"

[patch.crates-io]
redis = { git = "https://github.com/aumetra/redis-rs.git", rev = "3c4ee09d432a69e1d87d66dcba14c519467c9b81" }
typed-builder = { git = "https://github.com/idanarye/rust-typed-builder.git", rev = "fd1bd8336aeb0dc334060635e2a6a1d8dc329e3c" }
4 changes: 2 additions & 2 deletions crates/kitsune-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ edition.workspace = true
version.workspace = true

[dependencies]
async-trait = "0.1.73"
async-trait = "0.1.74"
deadpool-redis = "0.13.0"
derive_builder = "0.12.0"
enum_dispatch = "0.3.12"
moka = { version = "0.12.1", features = ["sync"] }
redis = "0.23.3"
serde = "1.0.189"
simd-json = "0.12.0"
thiserror = "1.0.49"
tracing = "0.1.39"
typed-builder = "0.17.0"

[dev-dependencies]
tokio = { version = "1.33.0", features = ["macros", "rt"] }
17 changes: 5 additions & 12 deletions crates/kitsune-cache/src/redis.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
use super::{CacheBackend, CacheResult};
use async_trait::async_trait;
use derive_builder::Builder;
use redis::AsyncCommands;
use serde::{de::DeserializeOwned, Serialize};
use std::{fmt::Display, marker::PhantomData, time::Duration};
use typed_builder::TypedBuilder;

#[derive(Builder)]
#[builder(pattern = "owned")]
#[derive(TypedBuilder)]
pub struct Redis<K, V>
where
K: ?Sized,
{
#[builder(default = "\"DEFAULT-REDIS-CACHER\".into()")]
#[builder(default = "DEFAULT-REDIS-CACHER".into())]
namespace: String,
#[builder(setter(into))]
prefix: String,
redis_conn: deadpool_redis::Pool,
ttl: Duration,

// Type phantom data
#[builder(setter(skip))]
#[builder(default, setter(skip))]
_key: PhantomData<K>,
#[builder(setter(skip))]
#[builder(default, setter(skip))]
_value: PhantomData<V>,
}

Expand All @@ -39,12 +38,6 @@ where
.prefix(prefix)
.ttl(ttl)
.build()
.unwrap()
}

#[must_use]
pub fn builder() -> RedisBuilder<K, V> {
RedisBuilder::default()
}

fn compute_key(&self, key: impl Display) -> String {
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-captcha/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version.workspace = true
edition.workspace = true

[dependencies]
async-trait = "0.1.73"
async-trait = "0.1.74"
enum_dispatch = "0.3.12"
http = "0.2.9"
kitsune-http-client = { path = "../kitsune-http-client" }
Expand All @@ -13,4 +13,4 @@ serde_urlencoded = "0.7.1"
simd-json = "0.12.0"
strum = { version = "0.25.0", features = ["derive"] }
thiserror = "1.0.49"
typed-builder = "0.16.2"
typed-builder = "0.17.0"
6 changes: 3 additions & 3 deletions crates/kitsune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ammonia = "3.3.0"
argon2 = "0.5.2"
async-recursion = "1.0.5"
async-stream = "0.3.5"
async-trait = "0.1.73"
async-trait = "0.1.74"
athena = { path = "../../lib/athena" }
autometrics = { version = "0.6.0", default-features = false }
base64-simd = "0.8.0"
Expand All @@ -20,7 +20,7 @@ diesel = "2.1.3"
diesel-async = { version = "0.4.1", features = ["postgres"] }
eyre = "0.6.8"
futures-util = "0.3.28"
garde = { version = "0.15.0", default-features = false, features = [
garde = { version = "0.16.0", default-features = false, features = [
"derive",
"email",
"email-idna",
Expand Down Expand Up @@ -67,7 +67,7 @@ time = "0.3.30"
tokio = { version = "1.33.0", features = ["macros", "rt"] }
toml = { version = "0.8.2", default-features = false, features = ["parse"] }
tracing = "0.1.39"
typed-builder = "0.16.2"
typed-builder = "0.17.0"
url = "2.4.1"
zxcvbn = { version = "2.2.2", default-features = false }

Expand Down
1 change: 0 additions & 1 deletion crates/kitsune-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ where
.redis_conn(pool.clone())
.ttl(Duration::from_secs(60)) // TODO: Parameterise this
.build()
.expect("[Bug] Failed to build the Redis cache")
.into()
}
};
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ speedy-uuid = { path = "../../lib/speedy-uuid", features = ["diesel"] }
thiserror = "1.0.49"
tokio = { version = "1.33.0", features = ["rt"] }
tracing-log = "0.1.3"
typed-builder = "0.16.2"
typed-builder = "0.17.0"
4 changes: 2 additions & 2 deletions crates/kitsune-email/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ignored = ["askama_axum"] # See reason below.
[dependencies]
askama = "0.12.1"
askama_axum = "0.3.0" # Damn it, cargo. Because "kitsune" uses "askama" with the axum feature, we have to have the crate available here as well..
lettre = { version = "0.10.4", default-features = false, features = [
lettre = { version = "0.11.0", default-features = false, features = [
"builder",
"hostname",
"pool",
Expand All @@ -24,4 +24,4 @@ mrml = { version = "2.0.0-rc4", default-features = false, features = [
"render",
] }
thiserror = "1.0.49"
typed-builder = "0.16.2"
typed-builder = "0.17.0"
2 changes: 1 addition & 1 deletion crates/kitsune-embed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ once_cell = "1.18.0"
scraper = { version = "0.17.1", default-features = false }
smol_str = "0.2.0"
thiserror = "1.0.49"
typed-builder = "0.16.2"
typed-builder = "0.17.0"
2 changes: 1 addition & 1 deletion crates/kitsune-http-signatures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ base64-simd = "0.8.0"
derive_builder = "0.12.0"
http = "0.2.9"
rayon = "1.8.0"
ring = { version = "0.17.3", features = ["std"] }
ring = { version = "0.17.4", features = ["std"] }
time = { version = "0.3.30", default-features = false, features = [
"formatting",
"parsing",
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-messaging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition.workspace = true

[dependencies]
ahash = "0.8.3"
async-trait = "0.1.73"
async-trait = "0.1.74"
futures-util = "0.3.28"
kitsune-retry-policies = { path = "../kitsune-retry-policies" }
pin-project-lite = "0.2.13"
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-search/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition.workspace = true
version.workspace = true

[dependencies]
async-trait = "0.1.73"
async-trait = "0.1.74"
diesel = "2.1.3"
diesel-async = "0.4.1"
diesel_full_text_search = { version = "2.1.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version.workspace = true
edition.workspace = true

[dependencies]
async-trait = "0.1.73"
async-trait = "0.1.74"
bytes = "1.5.0"
enum_dispatch = "0.3.12"
futures-util = "0.3.28"
Expand Down
4 changes: 2 additions & 2 deletions kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ askama = { version = "0.12.1", features = [
"with-axum",
], default-features = false }
askama_axum = "0.3.0"
async-trait = "0.1.73"
async-trait = "0.1.74"
axum = { version = "0.6.20", features = ["headers", "macros", "multipart"] }
axum-extra = { version = "0.8.0", features = [
"cookie",
Expand Down Expand Up @@ -76,7 +76,7 @@ tower-http = { version = "0.4.4", features = [
tracing = "0.1.39"
tracing-error = "0.2.0"
tracing-subscriber = "0.3.17"
typed-builder = "0.16.2"
typed-builder = "0.17.0"
url = "2.4.1"
utoipa = { version = "4.0.0", features = ["axum_extras", "uuid"] }
utoipa-swagger-ui = { version = "4.0.0", features = ["axum"] }
Expand Down
4 changes: 2 additions & 2 deletions lib/athena/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT"

[dependencies]
ahash = "0.8.3"
async-trait = "0.1.73"
async-trait = "0.1.74"
deadpool-redis = "0.13.0"
either = { version = "1.9.0", default-features = false }
futures-util = { version = "0.3.28", default-features = false }
Expand All @@ -29,7 +29,7 @@ speedy-uuid = { path = "../speedy-uuid", features = ["redis", "serde"] }
thiserror = "1.0.49"
tokio = { version = "1.33.0", features = ["macros", "rt", "sync"] }
tracing = "0.1.39"
typed-builder = "0.16.2"
typed-builder = "0.17.0"

[dev-dependencies]
tracing-subscriber = "0.3.17"
2 changes: 1 addition & 1 deletion lib/speedy-uuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ diesel = { version = "2.1.3", features = [
redis = { version = "0.23.3", default-features = false, optional = true }
serde = { version = "1.0.189", optional = true }
thiserror = "1.0.49"
uuid = { version = "1.4.1", features = ["fast-rng", "v7"] }
uuid = { version = "1.5.0", features = ["fast-rng", "v7"] }
uuid-simd = { version = "0.8.0", features = ["uuid"] }

0 comments on commit bffcff1

Please sign in to comment.