Skip to content

Commit

Permalink
Replace std::sync::Arc with triomphe::Arc (#530)
Browse files Browse the repository at this point in the history
* Replace `std::sync::Arc` with `triomphe::Arc`

* Fix typo
  • Loading branch information
aumetra authored May 9, 2024
1 parent 03e8ca3 commit 9911cc0
Show file tree
Hide file tree
Showing 75 changed files with 279 additions and 382 deletions.
231 changes: 52 additions & 179 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 @@ -124,3 +124,4 @@ install-updater = true

[patch.crates-io]
diesel-async = { git = "https://github.com/weiznich/diesel_async.git", rev = "d02798c67065d763154d7272dd0c09b39757d0f2" }
scraper = { git = "https://github.com/causal-agent/scraper.git", rev = "d67111f5cc0b7da6e6ff10e4549d87cf09ba3e5b" }
7 changes: 1 addition & 6 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,10 @@ path = "./mrf-storage"

# OpenTelemetry configuration
#
# Kitsune supports exporting traces and metrics via the OpenTelemetry Protocol (OTLP, for short)
# Kitsune supports exporting traces via the OpenTelemetry Protocol (OTLP, for short)
# It's by now the de-facto standard wire protocol for exporting telemetry data
#
# As of now, you can only export all data to a single endpoint.
# This configuration might become more granular in the future.
#
#[opentelemetry]
#metrics-transport = "http" # "grpc" or "http"
#metrics-endpoint = "http://localhost:4317"
#tracing-transport = "http" # "grpc" or "http"
#tracing-endpoint = "http://localhost:4317"

Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-activitypub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ license.workspace = true

[dependencies]
async-trait = "0.1.80"
autometrics = { version = "1.0.1", default-features = false }
base64-simd = "0.8.0"
diesel = "2.1.6"
diesel-async = "0.4.1"
Expand Down Expand Up @@ -37,6 +36,7 @@ sha2 = "0.10.8"
simd-json = "0.13.10"
speedy-uuid = { path = "../../lib/speedy-uuid" }
tracing = "0.1.40"
triomphe = "0.1.11"
typed-builder = "0.18.2"
url = "2.5.0"

Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-activitypub/src/deliverer/core.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use autometrics::autometrics;
use futures_util::{stream::FuturesUnordered, Stream, StreamExt};
use http::{Method, Request};
use kitsune_core::consts::USER_AGENT;
Expand Down Expand Up @@ -26,7 +25,6 @@ pub struct Deliverer {

impl Deliverer {
/// Deliver the activity to an inbox
#[autometrics(track_concurrency)]
#[instrument(skip_all, fields(%inbox_url, activity_url = %activity.id))]
pub async fn deliver(
&self,
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-activitypub/src/deliverer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use kitsune_service::attachment::AttachmentService;
use kitsune_type::ap::{ap_context, Activity, ActivityType, ObjectField};
use kitsune_url::UrlService;
use kitsune_util::try_join;
use std::sync::Arc;
use triomphe::Arc;
use typed_builder::TypedBuilder;

pub mod core;
Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-activitypub/src/fetcher/actor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::Fetcher;
use crate::process_attachments;
use autometrics::autometrics;
use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl;
use kitsune_cache::CacheBackend;
Expand All @@ -23,7 +22,6 @@ impl Fetcher {
///
/// - Panics if the URL doesn't contain a host section
#[instrument(skip(self))]
#[autometrics(track_concurrency)]
pub(crate) async fn fetch_actor(
&self,
opts: AccountFetchOptions<'_>,
Expand Down
5 changes: 3 additions & 2 deletions crates/kitsune-activitypub/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use kitsune_config::language_detection::Configuration as LanguageDetectionConfig
use kitsune_core::{
consts::USER_AGENT,
traits::{
coerce::CoerceResolver,
fetcher::{AccountFetchOptions, PostFetchOptions},
Fetcher as FetcherTrait, Resolver,
},
Expand All @@ -21,7 +22,7 @@ use kitsune_http_client::Client;
use kitsune_type::jsonld::RdfNode;
use mime::Mime;
use serde::de::DeserializeOwned;
use std::sync::Arc;
use triomphe::Arc;
use typed_builder::TypedBuilder;
use url::Url;

Expand Down Expand Up @@ -120,7 +121,7 @@ impl Fetcher {
#[async_trait]
impl FetcherTrait for Fetcher {
fn resolver(&self) -> Arc<dyn Resolver> {
Arc::new(self.resolver.clone())
Arc::new(self.resolver.clone()).coerce()
}

async fn fetch_account(&self, opts: AccountFetchOptions<'_>) -> Result<Option<Account>> {
Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-activitypub/src/fetcher/object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::Fetcher;
use crate::{process_new_object, ProcessNewObject};
use autometrics::autometrics;
use diesel::{ExpressionMethods, OptionalExtension, QueryDsl, SelectableHelper};
use diesel_async::RunQueryDsl;
use kitsune_cache::CacheBackend;
Expand All @@ -13,7 +12,6 @@ pub const MAX_FETCH_DEPTH: u32 = 15;

impl Fetcher {
#[instrument(skip(self))]
#[autometrics(track_concurrency)]
pub(crate) async fn fetch_object(&self, url: &str, call_depth: u32) -> Result<Option<Post>> {
if call_depth > MAX_FETCH_DEPTH {
return Ok(None);
Expand Down
16 changes: 5 additions & 11 deletions crates/kitsune-activitypub/tests/fetcher/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use diesel_async::RunQueryDsl;
use kitsune_activitypub::Fetcher;
use kitsune_cache::NoopCache;
use kitsune_config::instance::FederationFilterConfiguration;
use kitsune_core::traits::Fetcher as _;
use kitsune_core::traits::{coerce::CoerceResolver, Fetcher as _};
use kitsune_db::{
model::{account::Account, media_attachment::MediaAttachment},
schema::{accounts, media_attachments},
Expand All @@ -16,8 +16,8 @@ use kitsune_search::NoopSearchService;
use kitsune_test::{database_test, language_detection_config};
use kitsune_webfinger::Webfinger;
use pretty_assertions::assert_eq;
use std::sync::Arc;
use tower::service_fn;
use triomphe::Arc;

#[tokio::test]
async fn fetch_actor() {
Expand All @@ -36,10 +36,7 @@ async fn fetch_actor() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down Expand Up @@ -78,7 +75,7 @@ async fn fetch_emoji() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down Expand Up @@ -129,10 +126,7 @@ async fn fetch_note() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down
20 changes: 6 additions & 14 deletions crates/kitsune-activitypub/tests/fetcher/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use hyper::{body::Bytes, Request, Response};
use kitsune_activitypub::Fetcher;
use kitsune_cache::NoopCache;
use kitsune_config::instance::FederationFilterConfiguration;
use kitsune_core::traits::Fetcher as _;
use kitsune_core::traits::{coerce::CoerceResolver, Fetcher as _};
use kitsune_federation_filter::FederationFilter;
use kitsune_http_client::Client;
use kitsune_search::NoopSearchService;
use kitsune_test::{assert_display_eq, database_test, language_detection_config};
use kitsune_webfinger::Webfinger;
use std::{convert::Infallible, sync::Arc};
use std::convert::Infallible;
use tower::service_fn;
use triomphe::Arc;

macro_rules! assert_blocked {
($error:expr) => {
Expand Down Expand Up @@ -46,10 +47,7 @@ async fn federation_allow() {
.clone()
.client(client.clone())
.language_detection_config(language_detection_config())
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.build();

assert_blocked!(fetcher
Expand All @@ -67,10 +65,7 @@ async fn federation_allow() {
.clone()
.client(client.clone())
.language_detection_config(language_detection_config())
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.build();

assert!(matches!(
Expand Down Expand Up @@ -106,10 +101,7 @@ async fn federation_deny() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down
10 changes: 4 additions & 6 deletions crates/kitsune-activitypub/tests/fetcher/infinite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use iso8601_timestamp::Timestamp;
use kitsune_activitypub::{fetcher::MAX_FETCH_DEPTH, Fetcher};
use kitsune_cache::NoopCache;
use kitsune_config::instance::FederationFilterConfiguration;
use kitsune_core::traits::Fetcher as _;
use kitsune_core::traits::{coerce::CoerceResolver, Fetcher as _};
use kitsune_federation_filter::FederationFilter;
use kitsune_http_client::Client;
use kitsune_search::NoopSearchService;
Expand All @@ -16,12 +16,10 @@ use kitsune_type::ap::{
use kitsune_webfinger::Webfinger;
use std::{
convert::Infallible,
sync::{
atomic::{AtomicU32, Ordering},
Arc,
},
sync::atomic::{AtomicU32, Ordering},
};
use tower::service_fn;
use triomphe::Arc;

#[tokio::test]
async fn fetch_infinitely_long_reply_chain() {
Expand Down Expand Up @@ -104,7 +102,7 @@ async fn fetch_infinitely_long_reply_chain() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down
20 changes: 6 additions & 14 deletions crates/kitsune-activitypub/tests/fetcher/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use hyper::Request;
use kitsune_activitypub::Fetcher;
use kitsune_cache::NoopCache;
use kitsune_config::instance::FederationFilterConfiguration;
use kitsune_core::traits::Fetcher as _;
use kitsune_core::traits::{coerce::CoerceResolver, Fetcher as _};
use kitsune_federation_filter::FederationFilter;
use kitsune_http_client::Client;
use kitsune_search::NoopSearchService;
use kitsune_test::{assert_display_eq, database_test, language_detection_config};
use kitsune_webfinger::Webfinger;
use std::{convert::Infallible, sync::Arc};
use std::convert::Infallible;
use tower::service_fn;
use triomphe::Arc;

#[tokio::test]
async fn check_ap_id_authority() {
Expand All @@ -38,10 +39,7 @@ async fn check_ap_id_authority() {
.clone()
.client(client.clone())
.language_detection_config(language_detection_config())
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.build();

// The mock HTTP client ensures that the fetcher doesn't access the correct server
Expand All @@ -64,10 +62,7 @@ async fn check_ap_id_authority() {
.clone()
.client(client.clone())
.language_detection_config(language_detection_config())
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.build();

let _ = fetcher
Expand Down Expand Up @@ -100,10 +95,7 @@ async fn check_ap_content_type() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down
15 changes: 5 additions & 10 deletions crates/kitsune-activitypub/tests/fetcher/webfinger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ use hyper::{Request, Response};
use kitsune_activitypub::Fetcher;
use kitsune_cache::NoopCache;
use kitsune_config::instance::FederationFilterConfiguration;
use kitsune_core::traits::Fetcher as _;
use kitsune_core::traits::{coerce::CoerceResolver, Fetcher as _};
use kitsune_federation_filter::FederationFilter;
use kitsune_http_client::Client;
use kitsune_search::NoopSearchService;
use kitsune_test::{database_test, language_detection_config};
use kitsune_type::webfinger::{Link, Resource};
use kitsune_webfinger::Webfinger;
use pretty_assertions::assert_eq;
use std::{convert::Infallible, sync::Arc};
use std::convert::Infallible;
use tower::service_fn;
use triomphe::Arc;

#[tokio::test]
async fn fetch_actor_with_custom_acct() {
Expand Down Expand Up @@ -57,10 +58,7 @@ async fn fetch_actor_with_custom_acct() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down Expand Up @@ -138,10 +136,7 @@ async fn ignore_fake_webfinger_acct() {
)
.language_detection_config(language_detection_config())
.search_backend(NoopSearchService)
.resolver(Arc::new(Webfinger::with_client(
client,
Arc::new(NoopCache.into()),
)))
.resolver(Arc::new(Webfinger::with_client(client, Arc::new(NoopCache.into()))).coerce())
.account_cache(Arc::new(NoopCache.into()))
.post_cache(Arc::new(NoopCache.into()))
.build();
Expand Down
1 change: 1 addition & 0 deletions crates/kitsune-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ redis = { version = "0.25.3", default-features = false, features = [
serde = "1.0.201"
simd-json = "0.13.10"
tracing = "0.1.40"
triomphe = "0.1.11"
typed-builder = "0.18.2"

[dev-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion crates/kitsune-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ extern crate tracing;
use enum_dispatch::enum_dispatch;
use kitsune_error::Result;
use serde::{de::DeserializeOwned, Serialize};
use std::{fmt::Display, sync::Arc};
use std::fmt::Display;
use triomphe::Arc;

pub use self::in_memory::InMemory as InMemoryCache;
pub use self::redis::Redis as RedisCache;
Expand Down
2 changes: 0 additions & 2 deletions crates/kitsune-config/src/open_telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ pub enum Transport {
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct Configuration {
pub metrics_transport: Transport,
pub metrics_endpoint: SmolStr,
pub tracing_transport: Transport,
pub tracing_endpoint: SmolStr,
}
3 changes: 3 additions & 0 deletions crates/kitsune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ async-trait = "0.1.80"
const_format = "0.2.32"
kitsune-db = { path = "../kitsune-db" }
kitsune-error = { path = "../kitsune-error" }
paste = "1.0.15"
serde = { version = "1.0.201", features = ["derive"] }
triomphe = { version = "0.1.11", features = ["unsize"] }
typed-builder = "0.18.2"
unsize = "1.1.0"

[build-dependencies]
vergen = { version = "8.3.1", features = ["build", "git", "gitcl"] }
Expand Down
Loading

0 comments on commit 9911cc0

Please sign in to comment.