use crate::{
check_apub_id_valid_with_strictness,
- fetch_local_site_data,
+ local_site_data_cached,
objects::read_from_string_or_source_opt,
protocol::{
objects::{instance::Instance, LanguageTag},
data: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- Site::read_from_apub_id(data.pool(), object_id)
+ Site::read_from_apub_id(&mut data.pool(), &object_id.into())
.await?
.map(Into::into),
)
#[tracing::instrument(skip_all)]
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, LemmyError> {
let site_id = self.id;
- let langs = SiteLanguage::read(data.pool(), site_id).await?;
- let language = LanguageTag::new_multiple(langs, data.pool()).await?;
+ let langs = SiteLanguage::read(&mut data.pool(), site_id).await?;
+ let language = LanguageTag::new_multiple(langs, &mut data.pool()).await?;
let instance = Instance {
kind: ApplicationType::Application,
expected_domain: &Url,
data: &Data<Self::DataType>,
) -> Result<(), LemmyError> {
- let local_site_data = fetch_local_site_data(data.pool()).await?;
-
- check_apub_id_valid_with_strictness(apub.id.inner(), true, &local_site_data, data.settings())?;
+ check_apub_id_valid_with_strictness(apub.id.inner(), true, data).await?;
verify_domains_match(expected_domain, apub.id.inner())?;
+ let local_site_data = local_site_data_cached(&mut data.pool()).await?;
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
-
check_slurs(&apub.name, slur_regex)?;
check_slurs_opt(&apub.summary, slur_regex)?;
+
Ok(())
}
#[tracing::instrument(skip_all)]
async fn from_json(apub: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, LemmyError> {
let domain = apub.id.inner().domain().expect("group id has domain");
- let instance = DbInstance::read_or_create(data.pool(), domain.to_string()).await?;
+ let instance = DbInstance::read_or_create(&mut data.pool(), domain.to_string()).await?;
let site_form = SiteInsertForm {
name: apub.name.clone(),
private_key: None,
instance_id: instance.id,
};
- let languages = LanguageTag::to_language_id_multiple(apub.language, data.pool()).await?;
+ let languages = LanguageTag::to_language_id_multiple(apub.language, &mut data.pool()).await?;
- let site = Site::create(data.pool(), &site_form).await?;
- SiteLanguage::update(data.pool(), languages, &site).await?;
+ let site = Site::create(&mut data.pool(), &site_form).await?;
+ SiteLanguage::update(&mut data.pool(), languages, &site).await?;
Ok(site.into())
}
}
debug!("Failed to dereference site for {}: {}", &instance_id, e);
let domain = instance_id.domain().expect("has domain");
Ok(
- DbInstance::read_or_create(context.pool(), domain.to_string())
+ DbInstance::read_or_create(&mut context.pool(), domain.to_string())
.await?
.id,
)
}
}
-pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
+pub(crate) async fn remote_instance_inboxes(pool: &mut DbPool<'_>) -> Result<Vec<Url>, LemmyError> {
Ok(
Site::read_remote_sites(pool)
.await?
site
}
- #[actix_rt::test]
+ #[tokio::test]
#[serial]
async fn test_parse_lemmy_instance() {
let context = init_context().await;
assert_eq!(site.name, "Enterprise");
assert_eq!(site.description.as_ref().unwrap().len(), 15);
- Site::delete(context.pool(), site.id).await.unwrap();
+ Site::delete(&mut context.pool(), site.id).await.unwrap();
}
}