Skip to content

Commit

Permalink
Add masto-id-convert crate to monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Oct 27, 2023
1 parent 87f0ceb commit ff5697c
Show file tree
Hide file tree
Showing 28 changed files with 353 additions and 133 deletions.
216 changes: 131 additions & 85 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ members = [
"kitsune-cli",
"kitsune-job-runner",
"lib/athena",
"lib/masto-id-convert",
"lib/post-process",
"lib/speedy-uuid",
]
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ deadpool-redis = "0.13.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"
serde = "1.0.190"
simd-json = "0.13.3"
thiserror = "1.0.50"
tracing = "0.1.40"
typed-builder = "0.18.0"
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 @@ -8,9 +8,9 @@ async-trait = "0.1.74"
enum_dispatch = "0.3.12"
http = "0.2.9"
kitsune-http-client = { path = "../kitsune-http-client" }
serde = { version = "1.0.189", features = ["derive"] }
serde = { version = "1.0.190", features = ["derive"] }
serde_urlencoded = "0.7.1"
simd-json = "0.12.0"
simd-json = "0.13.3"
strum = { version = "0.25.0", features = ["derive"] }
thiserror = "1.0.50"
typed-builder = "0.18.0"
4 changes: 2 additions & 2 deletions crates/kitsune-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version.workspace = true

[dependencies]
eyre = "0.6.8"
serde = { version = "1.0.189", features = ["derive"] }
serde = { version = "1.0.190", features = ["derive"] }
smol_str = { version = "0.2.0", features = ["serde"] }
tokio = { version = "1.33.0", features = ["fs"] }
toml = { version = "0.8.4", default-features = false, features = ["parse"] }
toml = { version = "0.8.6", default-features = false, features = ["parse"] }
12 changes: 6 additions & 6 deletions crates/kitsune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ derive_builder = "0.12.0"
diesel = "2.1.3"
diesel-async = { version = "0.4.1", features = ["postgres"] }
eyre = "0.6.8"
futures-util = "0.3.28"
garde = { version = "0.16.0", default-features = false, features = [
futures-util = "0.3.29"
garde = { version = "0.16.1", default-features = false, features = [
"derive",
"email",
"email-idna",
Expand Down Expand Up @@ -57,12 +57,12 @@ pulldown-cmark = { version = "0.9.3", default-features = false, features = [
"simd",
] }
rand = "0.8.5"
rsa = "0.9.2"
rsa = "0.9.3"
rusty-s3 = { version = "0.5.0", default-features = false }
scoped-futures = "0.1.3"
serde = { version = "1.0.189", features = ["derive"] }
serde = { version = "1.0.190", features = ["derive"] }
sha2 = "0.10.8"
simd-json = "0.12.0"
simd-json = "0.13.3"
smol_str = "0.2.0"
speedy-uuid = { path = "../../lib/speedy-uuid", features = ["diesel"] }
thiserror = "1.0.50"
Expand Down Expand Up @@ -90,5 +90,5 @@ kitsune-test = { path = "../kitsune-test" }
pretty_assertions = "1.4.0"
redis = "0.23.3"
serial_test = "2.0.0"
tempfile = "3.8.0"
tempfile = "3.8.1"
tower = "0.4.13"
6 changes: 3 additions & 3 deletions crates/kitsune-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ kitsune-language = { path = "../kitsune-language" }
kitsune-type = { path = "../kitsune-type" }
num-derive = "0.4.1"
num-traits = "0.2.17"
serde = { version = "1.0.189", features = ["derive"] }
simd-json = "0.12.0"
serde = { version = "1.0.190", features = ["derive"] }
simd-json = "0.13.3"
speedy-uuid = { path = "../../lib/speedy-uuid", features = ["diesel"] }
thiserror = "1.0.50"
tracing-log = "0.1.4"
tracing-log = "0.2.0"
typed-builder = "0.18.0"
2 changes: 1 addition & 1 deletion 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.11.0", default-features = false, features = [
lettre = { version = "0.11.1", default-features = false, features = [
"builder",
"hostname",
"pool",
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-embed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ iso8601-timestamp = "0.2.12"
kitsune-db = { path = "../kitsune-db" }
kitsune-http-client = { path = "../kitsune-http-client" }
once_cell = "1.18.0"
scraper = { version = "0.17.1", default-features = false }
scraper = { version = "0.18.0", default-features = false }
smol_str = "0.2.0"
thiserror = "1.0.50"
typed-builder = "0.18.0"
8 changes: 4 additions & 4 deletions crates/kitsune-http-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition.workspace = true

[dependencies]
bytes = "1.5.0"
futures-core = "0.3.28"
futures-core = "0.3.29"
headers = "0.3.9"
http-body = "0.4.5"
hyper = { version = "0.14.27", features = [
Expand All @@ -15,12 +15,12 @@ hyper = { version = "0.14.27", features = [
"http2",
"runtime",
] }
hyper-rustls = { version = "0.24.1", features = ["http2"] }
hyper-rustls = { version = "0.24.2", features = ["http2"] }
kitsune-http-signatures = { path = "../kitsune-http-signatures" }
kitsune-type = { path = "../kitsune-type" }
pin-project-lite = "0.2.13"
serde = "1.0.189"
simd-json = "0.12.0"
serde = "1.0.190"
simd-json = "0.13.3"
tower = { version = "0.4.13", features = ["util"] }
tower-http = { version = "0.4.4", features = [
# Explicitly exclude `zstd`
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-http-client/tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::convert::Infallible;
use hyper::Response;
use hyper::{Body, Request};
use kitsune_http_client::Client;
use simd_json::{OwnedValue, ValueAccess};
use simd_json::{base::ValueAsScalar, OwnedValue};
use tower::service_fn;

#[tokio::test]
Expand Down
8 changes: 4 additions & 4 deletions crates/kitsune-messaging/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ version.workspace = true
edition.workspace = true

[dependencies]
ahash = "0.8.5"
ahash = "0.8.6"
async-trait = "0.1.74"
futures-util = "0.3.28"
futures-util = "0.3.29"
kitsune-retry-policies = { path = "../kitsune-retry-policies" }
pin-project-lite = "0.2.13"
redis = { version = "0.23.3", features = [
"aio",
"connection-manager",
"tokio-rustls-comp",
] }
serde = "1.0.189"
simd-json = "0.12.0"
serde = "1.0.190"
simd-json = "0.13.3"
tokio = { version = "1.33.0", features = ["macros", "rt", "sync"] }
tokio-stream = { version = "0.1.14", features = ["sync"] }
tracing = "0.1.40"
4 changes: 2 additions & 2 deletions crates/kitsune-search/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ diesel = "2.1.3"
diesel-async = "0.4.1"
diesel_full_text_search = { version = "2.1.1", default-features = false }
enum_dispatch = "0.3.12"
futures-util = "0.3.28"
futures-util = "0.3.29"
kitsune-db = { path = "../kitsune-db" }
kitsune-language = { path = "../kitsune-language" }
serde = { version = "1.0.189", features = ["derive"] }
serde = { version = "1.0.190", features = ["derive"] }
speedy-uuid = { path = "../../lib/speedy-uuid" }
strum = { version = "0.25.0", features = ["derive"] }
thiserror = "1.0.50"
Expand Down
6 changes: 3 additions & 3 deletions crates/kitsune-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ edition.workspace = true
async-trait = "0.1.74"
bytes = "1.5.0"
enum_dispatch = "0.3.12"
futures-util = "0.3.28"
futures-util = "0.3.29"
http = "0.2.9"
hyper = { version = "0.14.27", features = ["stream"] }
kitsune-http-client = { path = "../kitsune-http-client" }
rusty-s3 = { version = "0.5.0", default-features = false }
tokio = { version = "1.33.0", features = ["fs", "io-util"] }
tokio-util = { version = "0.7.9", features = ["io"] }
tokio-util = { version = "0.7.10", features = ["io"] }

[dev-dependencies]
tempfile = "3.8.0"
tempfile = "3.8.1"
tokio = { version = "1.33.0", features = ["macros", "rt"] }
2 changes: 1 addition & 1 deletion crates/kitsune-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version.workspace = true
deadpool-redis = "0.13.0"
diesel = "2.1.3"
diesel-async = "0.4.1"
futures-util = "0.3.28"
futures-util = "0.3.29"
kitsune-db = { path = "../kitsune-db" }
pin-project-lite = "0.2.13"
redis = "0.23.3"
Expand Down
4 changes: 2 additions & 2 deletions crates/kitsune-type/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition.workspace = true

[dependencies]
iso8601-timestamp = "0.2.12"
serde = { version = "1.0.189", features = ["derive"] }
simd-json = "0.12.0"
serde = { version = "1.0.190", features = ["derive"] }
simd-json = "0.13.3"
smol_str = { version = "0.2.0", features = ["serde"] }
speedy-uuid = { path = "../../lib/speedy-uuid", features = ["serde"] }
utoipa = { version = "4.0.0", features = ["chrono", "uuid"] }
Expand Down
2 changes: 1 addition & 1 deletion kitsune-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ diesel-async = "0.4.1"
dotenvy = "0.15.7"
envy = "0.4.2"
kitsune-db = { path = "../crates/kitsune-db" }
serde = { version = "1.0.189", features = ["derive"] }
serde = { version = "1.0.190", features = ["derive"] }
speedy-uuid = { path = "../lib/speedy-uuid" }
tokio = { version = "1.33.0", features = ["full"] }
tracing-subscriber = "0.3.17"
Expand Down
2 changes: 1 addition & 1 deletion kitsune-job-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kitsune-observability = { path = "../crates/kitsune-observability" }
kitsune-retry-policies = { path = "../crates/kitsune-retry-policies" }
mimalloc = "0.1.39"
tokio = { version = "1.33.0", features = ["full"] }
toml = "0.8.4"
toml = "0.8.6"
tracing = "0.1.40"

[features]
10 changes: 5 additions & 5 deletions kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ der = { version = "0.7.8", features = ["std"] }
diesel = "2.1.3"
diesel-async = "0.4.1"
eyre = "0.6.8"
futures-util = "0.3.28"
futures-util = "0.3.29"
headers = "0.3.9"
http = "0.2.9"
human-panic = "1.2.1"
Expand Down Expand Up @@ -60,16 +60,16 @@ oxide-auth = "0.5.4"
oxide-auth-async = "0.1.1"
oxide-auth-axum = "0.3.0"
scoped-futures = "0.1.3"
serde = { version = "1.0.189", features = ["derive"] }
serde = { version = "1.0.190", features = ["derive"] }
serde_urlencoded = "0.7.1"
simd-json = "0.12.0"
simd-json = "0.13.3"
speedy-uuid = { path = "../lib/speedy-uuid" }
strum = { version = "0.25.0", features = ["derive", "phf"] }
tempfile = "3.8.0"
tempfile = "3.8.1"
thiserror = "1.0.50"
time = "0.3.30"
tokio = { version = "1.33.0", features = ["full"] }
tokio-util = { version = "0.7.9", features = ["compat"] }
tokio-util = { version = "0.7.10", features = ["compat"] }
tower-http = { version = "0.4.4", features = [
"catch-panic",
"cors",
Expand Down
2 changes: 1 addition & 1 deletion kitsune/src/http/handler/nodeinfo/two_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use kitsune_type::nodeinfo::two_one::{
Protocol, Services, Software, TwoOne, Usage, UsageUsers, Version,
};
use scoped_futures::ScopedFutureExt;
use simd_json::{Builder, OwnedValue};
use simd_json::{OwnedValue, ValueBuilder};

#[debug_handler(state = crate::state::Zustand)]
#[utoipa::path(
Expand Down
8 changes: 4 additions & 4 deletions lib/athena/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ version.workspace = true
license = "MIT"

[dependencies]
ahash = "0.8.5"
ahash = "0.8.6"
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 }
futures-util = { version = "0.3.29", default-features = false }
iso8601-timestamp = { version = "0.2.12", features = ["diesel-pg"] }
kitsune-retry-policies = { path = "../../crates/kitsune-retry-policies" }
once_cell = "1.18.0"
Expand All @@ -22,8 +22,8 @@ redis = { version = "0.23.3", default-features = false, features = [
"tokio-rustls-comp",
] }
retry-policies = "0.2.1"
serde = { version = "1.0.189", features = ["derive"] }
simd-json = "0.12.0"
serde = { version = "1.0.190", features = ["derive"] }
simd-json = "0.13.3"
smol_str = "0.2.0"
speedy-uuid = { path = "../speedy-uuid", features = ["redis", "serde"] }
thiserror = "1.0.50"
Expand Down
26 changes: 26 additions & 0 deletions lib/masto-id-convert/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "masto-id-convert"
version.workspace = true
edition.workspace = true

[[bench]]
name = "process"
harness = false

[dependencies]
lexical = { version = "6.1.1", default-features = false, features = [
"parse-integers",
] }
nanorand = { version = "0.7.0", default-features = false, features = [
"wyrand",
] }
uuid = { version = "1.5.0", default-features = false }

[features]
default = ["std"]
std = []

[dev-dependencies]
criterion = { version = "0.5.1", default-features = false }
time = "0.3.30"
uuid = { version = "1.5.0", features = ["v7"] }
28 changes: 28 additions & 0 deletions lib/masto-id-convert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# masto-id-convert

Convert a Mastodon snowflake ID into a UUID v7 while preserving the timestamp component. Fast.

## How?

The unix timestamp is preserved as-is, the 2-bytes sequence is stretched out via the WyRand PRNG algorithm.

## Performance

Tested inside a WSL2 installation on a Ryzen 5 3600X:

```text
process 110368129515784116
time: [16.675 ns 16.822 ns 17.037 ns]
change: [-1.2226% -0.3915% +0.4911%] (p = 0.37 > 0.05)
```

Processing a single Mastodon snowflake takes ~17ns

## License

`masto-id-convert` is licensed under the [MIT license](http://opensource.org/licenses/MIT).

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you,
shall be licensed as above, without any additional terms or conditions.
14 changes: 14 additions & 0 deletions lib/masto-id-convert/benches/process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn process_bench(c: &mut Criterion) {
c.bench_function("process integer 110368129515784116", |b| {
b.iter(|| masto_id_convert::process_u64(black_box(110368129515784116)))
});

c.bench_function("process ASCII 110368129515784116", |b| {
b.iter(|| masto_id_convert::process(black_box("110368129515784116")))
});
}

criterion_group!(benches, process_bench);
criterion_main!(benches);
14 changes: 14 additions & 0 deletions lib/masto-id-convert/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use time::OffsetDateTime;

fn main() {
let uuid = masto_id_convert::process("110368129515784116").unwrap();
println!("Converted UUID: {uuid}");
println!("UUID version: {}", uuid.get_version_num());
println!("UUID variant: {}", uuid.get_variant());

let (timestamp_seconds, timestamp_nanos) = uuid.get_timestamp().unwrap().to_unix();
let timestamp_nanos = ((timestamp_seconds as i128) * 1_000_000_000) + (timestamp_nanos as i128);
let uuid_timestamp = OffsetDateTime::from_unix_timestamp_nanos(timestamp_nanos).unwrap();

println!("Embedded timestamp: {uuid_timestamp}");
}
Loading

0 comments on commit ff5697c

Please sign in to comment.