feat: add index on audience for faster groups

This commit is contained in:
əlemi 2024-07-03 03:26:40 +02:00
parent d6e47f1acb
commit 64ab2c3bb9
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 31 additions and 0 deletions

View file

@ -14,6 +14,7 @@ mod m20240623_000001_add_dislikes_table;
mod m20240626_000001_add_notifications_table; mod m20240626_000001_add_notifications_table;
mod m20240628_000001_add_followers_following_indexes; mod m20240628_000001_add_followers_following_indexes;
mod m20240628_000002_add_credentials_activated; mod m20240628_000002_add_credentials_activated;
mod m20240703_000001_add_audience_index;
pub struct Migrator; pub struct Migrator;
@ -35,6 +36,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240626_000001_add_notifications_table::Migration), Box::new(m20240626_000001_add_notifications_table::Migration),
Box::new(m20240628_000001_add_followers_following_indexes::Migration), Box::new(m20240628_000001_add_followers_following_indexes::Migration),
Box::new(m20240628_000002_add_credentials_activated::Migration), Box::new(m20240628_000002_add_credentials_activated::Migration),
Box::new(m20240703_000001_add_audience_index::Migration),
] ]
} }
} }

View file

@ -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(())
}
}