From e0e957c7216b7bd9afe0f029d78003530e754b53 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 27 Jun 2023 19:19:15 +0200 Subject: [PATCH 1/2] Also search for url field when looking for existing note in database --- .../backend/src/remote/activitypub/db-resolver.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/remote/activitypub/db-resolver.ts b/packages/backend/src/remote/activitypub/db-resolver.ts index 44ff70c56c..6e448d4b17 100644 --- a/packages/backend/src/remote/activitypub/db-resolver.ts +++ b/packages/backend/src/remote/activitypub/db-resolver.ts @@ -80,8 +80,15 @@ export default class DbResolver { id: parsed.id, }); } else { - return await Notes.findOneBy({ - uri: parsed.uri, + return await Notes.findOne({ + where: [ + { + uri: parsed.uri, + }, + { + url: parsed.uri, + }, + ], }); } } From 9d56db0fbfd645b2325a37e77e409a1676769d13 Mon Sep 17 00:00:00 2001 From: Namekuji Date: Tue, 27 Jun 2023 15:34:30 -0400 Subject: [PATCH 2/2] index note url --- .../backend/native-utils/migration/src/lib.rs | 6 ++- .../src/m20230627_185451_index_note_url.rs | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 packages/backend/native-utils/migration/src/m20230627_185451_index_note_url.rs diff --git a/packages/backend/native-utils/migration/src/lib.rs b/packages/backend/native-utils/migration/src/lib.rs index 4835c2d3d7..94e2b08cc4 100644 --- a/packages/backend/native-utils/migration/src/lib.rs +++ b/packages/backend/native-utils/migration/src/lib.rs @@ -1,12 +1,16 @@ pub use sea_orm_migration::prelude::*; mod m20230531_180824_drop_reversi; +mod m20230627_185451_index_note_url; pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { fn migrations() -> Vec> { - vec![Box::new(m20230531_180824_drop_reversi::Migration)] + vec![ + Box::new(m20230531_180824_drop_reversi::Migration), + Box::new(m20230627_185451_index_note_url::Migration), + ] } } diff --git a/packages/backend/native-utils/migration/src/m20230627_185451_index_note_url.rs b/packages/backend/native-utils/migration/src/m20230627_185451_index_note_url.rs new file mode 100644 index 0000000000..ceffed9c41 --- /dev/null +++ b/packages/backend/native-utils/migration/src/m20230627_185451_index_note_url.rs @@ -0,0 +1,38 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .create_index( + Index::create() + .name("IDX_note_url") + .table(Note::Table) + .col(Note::Url) + .if_not_exists() + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_index( + Index::drop() + .name("IDX_note_url") + .table(Note::Table) + .to_owned(), + ) + .await + } +} + +/// Learn more at https://docs.rs/sea-query#iden +#[derive(Iden)] +enum Note { + Table, + Url, +}