From 64ab2c3bb97f049c2036cf1f86c81c9121666a35 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 3 Jul 2024 03:26:40 +0200 Subject: [PATCH] feat: add index on audience for faster groups --- upub/migrations/src/lib.rs | 2 ++ .../m20240703_000001_add_audience_index.rs | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 upub/migrations/src/m20240703_000001_add_audience_index.rs diff --git a/upub/migrations/src/lib.rs b/upub/migrations/src/lib.rs index 2d4f0a66..2a36a724 100644 --- a/upub/migrations/src/lib.rs +++ b/upub/migrations/src/lib.rs @@ -14,6 +14,7 @@ mod m20240623_000001_add_dislikes_table; mod m20240626_000001_add_notifications_table; mod m20240628_000001_add_followers_following_indexes; mod m20240628_000002_add_credentials_activated; +mod m20240703_000001_add_audience_index; pub struct Migrator; @@ -35,6 +36,7 @@ impl MigratorTrait for Migrator { Box::new(m20240626_000001_add_notifications_table::Migration), Box::new(m20240628_000001_add_followers_following_indexes::Migration), Box::new(m20240628_000002_add_credentials_activated::Migration), + Box::new(m20240703_000001_add_audience_index::Migration), ] } } diff --git a/upub/migrations/src/m20240703_000001_add_audience_index.rs b/upub/migrations/src/m20240703_000001_add_audience_index.rs new file mode 100644 index 00000000..aa79a388 --- /dev/null +++ b/upub/migrations/src/m20240703_000001_add_audience_index.rs @@ -0,0 +1,29 @@ +use sea_orm_migration::prelude::*; + +use crate::m20240524_000001_create_actor_activity_object_tables::Objects; + +#[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("index-objects-audience") + .table(Objects::Table) + .col(Objects::Audience) + .to_owned() + ) + .await?; + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .drop_index(Index::drop().name("index-objects-audience").table(Objects::Table).to_owned()) + .await?; + Ok(()) + } +}