]> Untitled Git - lemmy.git/commitdiff
Dont upsert Instance row every apub fetch (#2771)
authorNutomic <me@nutomic.com>
Wed, 1 Mar 2023 02:36:57 +0000 (03:36 +0100)
committerGitHub <noreply@github.com>
Wed, 1 Mar 2023 02:36:57 +0000 (21:36 -0500)
This is not necessary because the domain cant change, so we only
need to insert if no row exists for this domain.

Also fetch instance actor when parsing person, not only community

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
31 files changed:
crates/api/src/lib.rs
crates/apub/src/collections/community_moderators.rs
crates/apub/src/objects/community.rs
crates/apub/src/objects/instance.rs
crates/apub/src/objects/person.rs
crates/db_schema/src/aggregates/comment_aggregates.rs
crates/db_schema/src/aggregates/community_aggregates.rs
crates/db_schema/src/aggregates/person_aggregates.rs
crates/db_schema/src/aggregates/post_aggregates.rs
crates/db_schema/src/aggregates/site_aggregates.rs
crates/db_schema/src/impls/activity.rs
crates/db_schema/src/impls/actor_language.rs
crates/db_schema/src/impls/comment.rs
crates/db_schema/src/impls/comment_reply.rs
crates/db_schema/src/impls/community.rs
crates/db_schema/src/impls/federation_allowlist.rs
crates/db_schema/src/impls/federation_blocklist.rs
crates/db_schema/src/impls/instance.rs
crates/db_schema/src/impls/moderator.rs
crates/db_schema/src/impls/password_reset_request.rs
crates/db_schema/src/impls/person.rs
crates/db_schema/src/impls/person_mention.rs
crates/db_schema/src/impls/post.rs
crates/db_schema/src/impls/private_message.rs
crates/db_views/src/comment_report_view.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_report_view.rs
crates/db_views/src/post_view.rs
crates/db_views/src/private_message_report_view.rs
crates/db_views/src/registration_application_view.rs
src/code_migrations.rs

index 217002ab37a5b467855df4b2ddc86d1532384c76..5c23ec34528399b461f96a32ae725319c7b27c19 100644 (file)
@@ -78,7 +78,9 @@ mod tests {
     let secret = Secret::init(pool).await.unwrap();
     let settings = &SETTINGS.to_owned();
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("Gerry9812".into())
index 9616ddb306acc07a2608950233f87f5d770ffe52..5c05258d1e9f35951477f056756c8bef8ec2b1f3 100644 (file)
@@ -156,7 +156,7 @@ mod tests {
     let community = parse_lemmy_community(&context).await;
     let community_id = community.id;
 
-    let inserted_instance = Instance::create(context.pool(), "my_domain.tld")
+    let inserted_instance = Instance::read_or_create(context.pool(), "my_domain.tld".to_string())
       .await
       .unwrap();
 
index 9f8cfae60b4eacb51c0e6da404244a7e6bc9f4b6..7a1583ca09239ee5b107c7623a6df8c32114e50d 100644 (file)
@@ -26,7 +26,6 @@ use lemmy_db_schema::{
   source::{
     actor_language::CommunityLanguage,
     community::{Community, CommunityUpdateForm},
-    instance::Instance,
   },
   traits::{ApubActor, Crud},
 };
@@ -136,10 +135,9 @@ impl ApubObject for ApubCommunity {
     context: &LemmyContext,
     request_counter: &mut i32,
   ) -> Result<ApubCommunity, LemmyError> {
-    let apub_id = group.id.inner().clone();
-    let instance = Instance::create_from_actor_id(context.pool(), &apub_id).await?;
+    let instance_id = fetch_instance_actor_for_object(&group.id, context, request_counter).await?;
 
-    let form = Group::into_insert_form(group.clone(), instance.id);
+    let form = Group::into_insert_form(group.clone(), instance_id);
     let languages = LanguageTag::to_language_id_multiple(group.language, context.pool()).await?;
 
     let community = Community::create(context.pool(), &form).await?;
@@ -165,8 +163,6 @@ impl ApubObject for ApubCommunity {
         .ok();
     }
 
-    fetch_instance_actor_for_object(community.actor_id(), context, request_counter).await;
-
     Ok(community)
   }
 }
index fff79463bd6e17044944b46ff47eb0f3d873e403..8fa3976ac6b1c0e6e58cb868451a7bd5c34bcdd2 100644 (file)
@@ -20,6 +20,7 @@ use activitystreams_kinds::actor::ApplicationType;
 use chrono::NaiveDateTime;
 use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
 use lemmy_db_schema::{
+  newtypes::InstanceId,
   source::{
     actor_language::SiteLanguage,
     instance::Instance as DbInstance,
@@ -134,8 +135,8 @@ impl ApubObject for ApubSite {
     data: &Self::DataType,
     _request_counter: &mut i32,
   ) -> Result<Self, LemmyError> {
-    let apub_id = apub.id.inner().clone();
-    let instance = DbInstance::create_from_actor_id(data.pool(), &apub_id).await?;
+    let domain = apub.id.inner().domain().expect("group id has domain");
+    let instance = DbInstance::read_or_create(data.pool(), domain.to_string()).await?;
 
     let site_form = SiteInsertForm {
       name: apub.name.clone(),
@@ -178,19 +179,29 @@ impl Actor for ApubSite {
   }
 }
 
-/// try to fetch the instance actor (to make things like instance rules available)
-pub(in crate::objects) async fn fetch_instance_actor_for_object(
-  object_id: Url,
+/// Try to fetch the instance actor (to make things like instance rules available).
+pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + Clone>(
+  object_id: &T,
   context: &LemmyContext,
   request_counter: &mut i32,
-) {
-  // try to fetch the instance actor (to make things like instance rules available)
+) -> Result<InstanceId, LemmyError> {
+  let object_id: Url = object_id.clone().into();
   let instance_id = Site::instance_actor_id_from_url(object_id);
   let site = ObjectId::<ApubSite>::new(instance_id.clone())
     .dereference(context, local_instance(context).await, request_counter)
     .await;
-  if let Err(e) = site {
-    debug!("Failed to dereference site for {}: {}", instance_id, e);
+  match site {
+    Ok(s) => Ok(s.instance_id),
+    Err(e) => {
+      // Failed to fetch instance actor, its probably not a lemmy instance
+      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())
+          .await?
+          .id,
+      )
+    }
   }
 }
 
index 1b7e86d906b5874d12f6cf4a21bb1393a653e612..55bfcd29afe1567563d9253c68c94b5afa4d65a1 100644 (file)
@@ -23,10 +23,7 @@ use lemmy_api_common::{
   utils::{generate_outbox_url, local_site_opt_to_slur_regex},
 };
 use lemmy_db_schema::{
-  source::{
-    instance::Instance,
-    person::{Person as DbPerson, PersonInsertForm, PersonUpdateForm},
-  },
+  source::person::{Person as DbPerson, PersonInsertForm, PersonUpdateForm},
   traits::{ApubActor, Crud},
   utils::naive_now,
 };
@@ -149,8 +146,7 @@ impl ApubObject for ApubPerson {
     context: &LemmyContext,
     request_counter: &mut i32,
   ) -> Result<ApubPerson, LemmyError> {
-    let apub_id = person.id.inner().clone();
-    let instance = Instance::create_from_actor_id(context.pool(), &apub_id).await?;
+    let instance_id = fetch_instance_actor_for_object(&person.id, context, request_counter).await?;
 
     let person_form = PersonInsertForm {
       name: person.preferred_username,
@@ -173,13 +169,10 @@ impl ApubObject for ApubPerson {
       inbox_url: Some(person.inbox.into()),
       shared_inbox_url: person.endpoints.map(|e| e.shared_inbox.into()),
       matrix_user_id: person.matrix_user_id,
-      instance_id: instance.id,
+      instance_id,
     };
     let person = DbPerson::create(context.pool(), &person_form).await?;
 
-    let actor_id = person.actor_id.clone().into();
-    fetch_instance_actor_for_object(actor_id, context, request_counter).await;
-
     Ok(person.into())
   }
 }
index 56528a5fe6fa59f7307465797171329c50ae368f..f56fd8cbe50b6777aef32bfee83bf764a79ed78e 100644 (file)
@@ -38,7 +38,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("thommy_comment_agg".into())
index 96dbb8fb4d2440a45178209a20e164e79100aa94..2c2eaa78157901ccfcc885daeb6a497ded576552 100644 (file)
@@ -38,7 +38,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("thommy_community_agg".into())
index b8e1887a1225b0a359a32d93b2aefd368dc59f1c..6f804590845016db79490b97d44e6c8932ecb309 100644 (file)
@@ -38,7 +38,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("thommy_user_agg".into())
index dca5fb826970fd1d83180375c06f10629f0b9b89..848f2014b3cb02f3b76af39534f7a20078e445f7 100644 (file)
@@ -38,7 +38,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("thommy_community_agg".into())
index 8b4ccb3740c518bd8cb2d9a17e98e25ea37379db..719beb8f7b918d0b42fddbb35b6957084fdacab9 100644 (file)
@@ -35,7 +35,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("thommy_site_agg".into())
index a3137f355788305536c6fba81edc2a87a8367634..bdf0f1dc2d32d04781d85ea1df3c48e619e1a52c 100644 (file)
@@ -109,7 +109,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let creator_form = PersonInsertForm::builder()
       .name("activity_creator_ pm".into())
index d515d44f0afcf556fa135280e811582134dc6b9c..bf3e7ac987e1df1e21a14fe30f757a6dbc35cfc1 100644 (file)
@@ -404,7 +404,9 @@ mod tests {
   }
 
   async fn create_test_site(pool: &DbPool) -> (Site, Instance) {
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let site_form = SiteInsertForm::builder()
       .name("test site".to_string())
index 2dfae6dd2319ff2c6d8f936105b9c3c1c352ab06..2a9eeafedbdbaa15e13c8d56ac275a595889fd88 100644 (file)
@@ -277,7 +277,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("terry".into())
index 73ecd35898b84a26e59e4ffd1083504a1cf9e297..2489c982f17d1ca71041ce94c9ab03c2c7f46ada 100644 (file)
@@ -94,7 +94,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("terrylake".into())
index d1a4f2b6c34fa415f54105222ada626f769a948b..f341b5ed9eb21dfdd7151836fa543212c88f9a79 100644 (file)
@@ -423,7 +423,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("bobbee".into())
index 79efecc9a1ae890de989db602cd7e2df8a363c47..c71ffd1cf3088d6b850fef2c251be4834d978ac1 100644 (file)
@@ -21,7 +21,7 @@ impl FederationAllowList {
 
             for domain in list {
               // Upsert all of these as instances
-              let instance = Instance::create_conn(conn, &domain).await?;
+              let instance = Instance::read_or_create_with_conn(conn, domain).await?;
 
               let form = FederationAllowListForm {
                 instance_id: instance.id,
index 41f0ebe7c8690889df0686fc32fa9cc1fd7a5f30..917bf57a33668b24fffeb2b1443525a3eb88e524 100644 (file)
@@ -21,7 +21,7 @@ impl FederationBlockList {
 
             for domain in list {
               // Upsert all of these as instances
-              let instance = Instance::create_conn(conn, &domain).await?;
+              let instance = Instance::read_or_create_with_conn(conn, domain).await?;
 
               let form = FederationBlockListForm {
                 instance_id: instance.id,
index 473ca007e6015d334f6de3e3644c7270ae407b7d..e5a8caba39aa934a87e9189a934da54d517a265b 100644 (file)
@@ -6,36 +6,45 @@ use crate::{
 };
 use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
 use diesel_async::{AsyncPgConnection, RunQueryDsl};
-use url::Url;
 
 impl Instance {
-  async fn create_from_form_conn(
+  pub(crate) async fn read_or_create_with_conn(
     conn: &mut AsyncPgConnection,
-    form: &InstanceForm,
+    domain_: String,
   ) -> Result<Self, Error> {
-    // Do upsert on domain name conflict
-    insert_into(instance::table)
-      .values(form)
-      .on_conflict(instance::domain)
-      .do_update()
-      .set(form)
-      .get_result::<Self>(conn)
-      .await
+    use crate::schema::instance::domain;
+    // First try to read the instance row and return directly if found
+    let instance = instance::table
+      .filter(domain.eq(&domain_))
+      .first::<Self>(conn)
+      .await;
+    match instance {
+      Ok(i) => Ok(i),
+      Err(diesel::NotFound) => {
+        // Instance not in database yet, insert it
+        let form = InstanceForm::builder()
+          .domain(domain_)
+          .updated(Some(naive_now()))
+          .build();
+        insert_into(instance::table)
+          .values(&form)
+          // Necessary because this method may be called concurrently for the same domain. This
+          // could be handled with a transaction, but nested transactions arent allowed
+          .on_conflict(instance::domain)
+          .do_update()
+          .set(&form)
+          .get_result::<Self>(conn)
+          .await
+      }
+      e => e,
+    }
   }
-  pub async fn create(pool: &DbPool, domain: &str) -> Result<Self, Error> {
+
+  /// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one.
+  /// There is no need for update as the domain of an existing instance cant change.
+  pub async fn read_or_create(pool: &DbPool, domain: String) -> Result<Self, Error> {
     let conn = &mut get_conn(pool).await?;
-    Self::create_conn(conn, domain).await
-  }
-  pub async fn create_from_actor_id(pool: &DbPool, actor_id: &Url) -> Result<Self, Error> {
-    let domain = actor_id.host_str().expect("actor id missing a domain");
-    Self::create(pool, domain).await
-  }
-  pub async fn create_conn(conn: &mut AsyncPgConnection, domain: &str) -> Result<Self, Error> {
-    let form = InstanceForm::builder()
-      .domain(domain.to_string())
-      .updated(Some(naive_now()))
-      .build();
-    Self::create_from_form_conn(conn, &form).await
+    Self::read_or_create_with_conn(conn, domain).await
   }
   pub async fn delete(pool: &DbPool, instance_id: InstanceId) -> Result<usize, Error> {
     let conn = &mut get_conn(pool).await?;
@@ -43,6 +52,7 @@ impl Instance {
       .execute(conn)
       .await
   }
+  #[cfg(test)]
   pub async fn delete_all(pool: &DbPool) -> Result<usize, Error> {
     let conn = &mut get_conn(pool).await?;
     diesel::delete(instance::table).execute(conn).await
index 23be96146dde355671cbb5c87ca698296a3c1f22..7540e4871560e2882ca627afeece55d4f7b7bfcc 100644 (file)
@@ -549,7 +549,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_mod = PersonInsertForm::builder()
       .name("the mod".into())
index 4aa5599a0ce8e6edf0ffd5833cadaf61ff360028..ebe8a00ecff87738618c5327309caf65d94abbcb 100644 (file)
@@ -103,7 +103,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("thommy prw".into())
index fa7d2530fb8e86c9c921985b0295a984b22d72e4..13be5843350541cc84f443ae27f6f420324ef616 100644 (file)
@@ -285,7 +285,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("holly".into())
@@ -342,7 +344,9 @@ mod tests {
   #[serial]
   async fn follow() {
     let pool = &build_db_pool_for_tests().await;
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let person_form_1 = PersonInsertForm::builder()
       .name("erich".into())
index cf7e9e2d3fd23e5c124f8aea711a6fa851644bd1..559340e78823caef8aa2a98b590f631a6b93364d 100644 (file)
@@ -98,7 +98,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("terrylake".into())
index 9f5c64389b5f735343bbd932ce766cf7e3599d7c..8c5ffa8ad795a2a332ab97fe7ca28004bd652590 100644 (file)
@@ -360,7 +360,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("jim".into())
index b20fee89c79bac415886262d12066701a0d8317f..a30ac20e534f521365cf23f652672bc132646931 100644 (file)
@@ -111,7 +111,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let creator_form = PersonInsertForm::builder()
       .name("creator_pm".into())
index f4e94cc07f280e1f5172171e088162d9df1ae578..f9d2077fb28341342007cfe1b76e59baaa4fb157 100644 (file)
@@ -335,7 +335,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("timmy_crv".into())
index c1b38e3afb4e42d92be28620843a7bc9666a2395..4fb950a52b8237a2fc5e1c2a9a6b094d9141763b 100644 (file)
@@ -450,7 +450,9 @@ mod tests {
   }
 
   async fn init_data(pool: &DbPool) -> Data {
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("timmy".into())
index 523a19febbb778ecbabce7eed5d8ef63346d18a5..e2661d6d605f74cfed192d1d16796ccdc989a40d 100644 (file)
@@ -311,7 +311,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person = PersonInsertForm::builder()
       .name("timmy_prv".into())
index a7207aa9ad1f0625d654b8da612a13561c391a58..1427d948360cf5640dd153769339bb9b36335b80 100644 (file)
@@ -498,7 +498,9 @@ mod tests {
   }
 
   async fn init_data(pool: &DbPool) -> Data {
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let person_name = "tegan".to_string();
 
index 29cd5d0e2f360133c064eda4670f98ae27aabbf6..647256ade25a04624ef8969fd8a41ba2a449e811 100644 (file)
@@ -169,7 +169,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let new_person_1 = PersonInsertForm::builder()
       .name("timmy_mrv".into())
index 22f62a881e88bea979bdc780ac3349b22ccb6104..0b5fa05e188238d3bf273bcf04332e5a76a741fd 100644 (file)
@@ -186,7 +186,9 @@ mod tests {
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
 
-    let inserted_instance = Instance::create(pool, "my_domain.tld").await.unwrap();
+    let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
+      .await
+      .unwrap();
 
     let timmy_person_form = PersonInsertForm::builder()
       .name("timmy_rav".into())
index 5151611bdecd83364029fea0213ce07c434edbbb..07c29beacdb50f5e2817f290a5d7e1054d1ed8f7 100644 (file)
@@ -429,7 +429,7 @@ async fn initialize_local_site_2022_10_10(
     .expect("must have domain");
 
   // Upsert this to the instance table
-  let instance = Instance::create(pool, &domain).await?;
+  let instance = Instance::read_or_create(pool, domain).await?;
 
   if let Some(setup) = &settings.setup {
     let person_keypair = generate_actor_keypair()?;