Skip to content

Commit

Permalink
Index for queued mints and remove order by random for selecting rando…
Browse files Browse the repository at this point in the history
…m mint
  • Loading branch information
imabdulbasit committed Oct 11, 2023
1 parent 6593d73 commit 88c3dd1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion api/src/mutations/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,6 @@ impl Mutation {
let mint = CollectionMints::find()
.filter(collection_mints::Column::CollectionId.eq(drop.collection_id))
.filter(collection_mints::Column::CreationStatus.eq(CreationStatus::Queued))
.order_by(SimpleExpr::FunctionCall(Func::random()), Order::Asc)
.one(conn)
.await?
.ok_or(Error::new("No Queued mint found for the drop"))?;
Expand Down
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ mod m20230911_144938_make_compressed_column_optional;
mod m20230914_154759_add_job_trackings_table;
mod m20230915_111128_create_mints_creation_status_idx;
mod m20230922_150621_nullable_metadata_jsons_identifier_and_uri;
mod m20231011_202917_create_queued_mints_idx;

pub struct Migrator;

Expand Down Expand Up @@ -127,6 +128,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230915_111128_create_mints_creation_status_idx::Migration),
Box::new(m20230914_154759_add_job_trackings_table::Migration),
Box::new(m20230922_150621_nullable_metadata_jsons_identifier_and_uri::Migration),
Box::new(m20231011_202917_create_queued_mints_idx::Migration),
]
}
}
29 changes: 29 additions & 0 deletions migration/src/m20231011_202917_create_queued_mints_idx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use sea_orm_migration::{
prelude::*,
sea_orm::{ConnectionTrait, Statement},
};

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();

let stmt = Statement::from_string(
manager.get_database_backend(),
r#"CREATE INDEX IF NOT EXISTS queued_mints_idx ON collection_mints(creation_status)
where creation_status = 'queued';"#
.to_string(),
);

db.execute(stmt).await?;

Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}

0 comments on commit 88c3dd1

Please sign in to comment.