Skip to content

Commit

Permalink
use search service
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Oct 28, 2023
1 parent 9a955e1 commit 96c8553
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 108 deletions.
26 changes: 13 additions & 13 deletions crates/kitsune-core/src/activitypub/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use kitsune_db::{
};
use kitsune_embed::Client as EmbedClient;
use kitsune_http_client::Client;
use kitsune_search::{Search, SearchBackend};
use kitsune_search::SearchBackend;
use kitsune_type::{
ap::{actor::Actor, Object},
jsonld::RdfNode,
Expand Down Expand Up @@ -85,7 +85,7 @@ pub struct Fetcher {
embed_client: Option<EmbedClient>,
federation_filter: FederationFilterService,
#[builder(setter(into))]
search_service: Search,
search_backend: kitsune_search::Search,
webfinger: Webfinger,

// Caches
Expand Down Expand Up @@ -292,7 +292,7 @@ impl Fetcher {
})
.await?;

self.search_service
self.search_backend
.add_to_index(account.clone().into())
.await?;

Expand Down Expand Up @@ -346,7 +346,7 @@ impl Fetcher {
.embed_client(self.embed_client.as_ref())
.fetcher(self)
.object(Box::new(object))
.search_service(&self.search_service)
.search_backend(&self.search_backend)
.build();
let post = process_new_object(process_data).await?;

Expand Down Expand Up @@ -419,7 +419,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(Webfinger::with_client(client, Arc::new(NoopCache.into())))
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand Down Expand Up @@ -482,7 +482,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(Webfinger::with_client(client, Arc::new(NoopCache.into())))
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand Down Expand Up @@ -559,7 +559,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(Webfinger::with_client(client, Arc::new(NoopCache.into())))
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand Down Expand Up @@ -593,7 +593,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(Webfinger::with_client(client, Arc::new(NoopCache.into())))
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand Down Expand Up @@ -705,7 +705,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(Webfinger::with_client(client, Arc::new(NoopCache.into())))
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand All @@ -732,7 +732,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()));

Expand Down Expand Up @@ -798,7 +798,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(Webfinger::with_client(client, Arc::new(NoopCache.into())))
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand Down Expand Up @@ -827,7 +827,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()));

Expand Down Expand Up @@ -894,7 +894,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(Webfinger::with_client(client, Arc::new(NoopCache.into())))
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand Down
12 changes: 6 additions & 6 deletions crates/kitsune-core/src/activitypub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub struct ProcessNewObject<'a> {
embed_client: Option<&'a EmbedClient>,
object: Box<Object>,
fetcher: &'a Fetcher,
search_service: &'a Search,
search_backend: &'a Search,
}

#[derive(TypedBuilder)]
Expand All @@ -129,7 +129,7 @@ struct PreprocessedObject<'a> {
content_lang: Language,
db_pool: &'a PgPool,
object: Box<Object>,
search_service: &'a Search,
search_backend: &'a Search,
}

#[allow(clippy::missing_panics_doc)]
Expand All @@ -141,7 +141,7 @@ async fn preprocess_object(
embed_client,
mut object,
fetcher,
search_service,
search_backend: search_service,
}: ProcessNewObject<'_>,
) -> Result<PreprocessedObject<'_>> {
let attributed_to = object.attributed_to().ok_or(ApiError::BadRequest)?;
Expand Down Expand Up @@ -200,7 +200,7 @@ async fn preprocess_object(
content_lang,
db_pool,
object,
search_service,
search_backend: search_service,
})
}

Expand All @@ -214,7 +214,7 @@ pub async fn process_new_object(process_data: ProcessNewObject<'_>) -> Result<Po
content_lang,
db_pool,
object,
search_service,
search_backend: search_service,
} = preprocess_object(process_data).await?;

let post = db_pool
Expand Down Expand Up @@ -286,7 +286,7 @@ pub async fn update_object(process_data: ProcessNewObject<'_>) -> Result<Post> {
content_lang,
db_pool,
object,
search_service,
search_backend: search_service,
} = preprocess_object(process_data).await?;

let post = db_pool
Expand Down
12 changes: 9 additions & 3 deletions crates/kitsune-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use kitsune_search::{NoopSearchService, Search, SqlSearchService};
use kitsune_storage::{fs::Storage as FsStorage, s3::Storage as S3Storage, Storage};
use rusty_s3::{Bucket as S3Bucket, Credentials as S3Credentials};
use serde::{de::DeserializeOwned, Serialize};
use service::search::SearchService;
use std::{
fmt::Display,
str::FromStr,
Expand Down Expand Up @@ -216,7 +217,7 @@ pub async fn prepare_state(
let messaging_hub = prepare_messaging(config).await?;
let status_event_emitter = messaging_hub.emitter("event.status".into());

let search_service = prepare_search(&config.search, &db_pool).await?;
let search_backend = prepare_search(&config.search, &db_pool).await?;

let embed_client = config.embed.as_ref().map(|embed_config| {
EmbedClient::builder()
Expand All @@ -237,10 +238,15 @@ pub async fn prepare_state(
.federation_filter(federation_filter_service.clone())
.post_cache(prepare_cache(config, "ACTIVITYPUB-POST"))
.webfinger(webfinger.clone())
.search_service(search_service.clone())
.search_backend(search_backend.clone())
.user_cache(prepare_cache(config, "ACTIVITYPUB-USER"))
.build();

let search_service = SearchService::builder()
.fetcher(fetcher.clone())
.search_backend(search_backend.clone())
.build();

let job_service = JobService::builder().job_queue(job_queue).build();

let url_service = UrlService::builder()
Expand Down Expand Up @@ -296,7 +302,7 @@ pub async fn prepare_state(
.instance_service(instance_service.clone())
.job_service(job_service.clone())
.post_resolver(post_resolver)
.search_service(search_service.clone())
.search_backend(search_backend)
.status_event_emitter(status_event_emitter.clone())
.url_service(url_service.clone())
.build();
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-core/src/resolve/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod test {
})
.unwrap(),
)
.search_service(NoopSearchService)
.search_backend(NoopSearchService)
.webfinger(webfinger.clone())
.post_cache(Arc::new(NoopCache.into()))
.user_cache(Arc::new(NoopCache.into()))
Expand Down
10 changes: 5 additions & 5 deletions crates/kitsune-core/src/service/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use kitsune_db::{
};
use kitsune_embed::Client as EmbedClient;
use kitsune_language::{DetectionBackend, Language};
use kitsune_search::{Search, SearchBackend};
use kitsune_search::SearchBackend;
use scoped_futures::ScopedFutureExt;
use speedy_uuid::Uuid;
use typed_builder::TypedBuilder;
Expand Down Expand Up @@ -300,7 +300,7 @@ pub struct PostService {
instance_service: InstanceService,
job_service: JobService,
post_resolver: PostResolver,
search_service: Search,
search_backend: kitsune_search::Search,
status_event_emitter: PostEventEmitter,
url_service: UrlService,
}
Expand Down Expand Up @@ -502,7 +502,7 @@ impl PostService {
.await?;

if post.visibility == Visibility::Public || post.visibility == Visibility::Unlisted {
self.search_service
self.search_backend
.add_to_index(post.clone().into())
.await?;
}
Expand Down Expand Up @@ -548,7 +548,7 @@ impl PostService {
.await
.map_err(Error::Event)?;

self.search_service.remove_from_index(&post.into()).await?;
self.search_backend.remove_from_index(&post.into()).await?;

Ok(())
}
Expand Down Expand Up @@ -653,7 +653,7 @@ impl PostService {
.await?;

if post.visibility == Visibility::Public || post.visibility == Visibility::Unlisted {
self.search_service
self.search_backend
.update_in_index(post.clone().into())
.await?;
}
Expand Down
5 changes: 5 additions & 0 deletions crates/kitsune-core/src/service/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ pub struct SearchService {
}

impl SearchService {
#[must_use]
pub fn backend(&self) -> &kitsune_search::Search {
&self.search_backend
}

pub async fn search(&self, search: Search<'_>) -> Result<Vec<SearchResult>> {
search.validate(&())?;

Expand Down
5 changes: 2 additions & 3 deletions crates/kitsune-core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ use crate::{
account::AccountService, attachment::AttachmentService, captcha::CaptchaService,
federation_filter::FederationFilterService, instance::InstanceService, job::JobService,
mailing::MailingService, notification::NotificationService, post::PostService,
timeline::TimelineService, url::UrlService, user::UserService,
search::SearchService, timeline::TimelineService, url::UrlService, user::UserService,
},
webfinger::Webfinger,
};
use kitsune_db::PgPool;
use kitsune_embed::Client as EmbedClient;
use kitsune_search::Search;

/// Emitter collection
///
Expand All @@ -37,7 +36,7 @@ pub struct Service {
pub notification: NotificationService,
pub post: PostService,
pub instance: InstanceService,
pub search: Search,
pub search: SearchService,
pub timeline: TimelineService,
pub url: UrlService,
pub user: UserService,
Expand Down
Loading

0 comments on commit 96c8553

Please sign in to comment.