Merge pull request 'Fix note url resolver' (#10371) from e2net/calckey:fix/db-resolve-note-url into develop
Reviewed-on: https://codeberg.org/calckey/calckey/pulls/10371
This commit is contained in:
commit
80e90c7985
|
@ -1,12 +1,16 @@
|
||||||
pub use sea_orm_migration::prelude::*;
|
pub use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
mod m20230531_180824_drop_reversi;
|
mod m20230531_180824_drop_reversi;
|
||||||
|
mod m20230627_185451_index_note_url;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MigratorTrait for Migrator {
|
impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![Box::new(m20230531_180824_drop_reversi::Migration)]
|
vec![
|
||||||
|
Box::new(m20230531_180824_drop_reversi::Migration),
|
||||||
|
Box::new(m20230627_185451_index_note_url::Migration),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
|
}
|
|
@ -80,8 +80,15 @@ export default class DbResolver {
|
||||||
id: parsed.id,
|
id: parsed.id,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return await Notes.findOneBy({
|
return await Notes.findOne({
|
||||||
|
where: [
|
||||||
|
{
|
||||||
uri: parsed.uri,
|
uri: parsed.uri,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: parsed.uri,
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue