Skip to content

Commit

Permalink
feat(anni): migrate with commit=false
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Sep 5, 2024
1 parent 9b511eb commit 379bdfb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
12 changes: 10 additions & 2 deletions anni-metadata/queries/add-album.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,16 @@ fragment AlbumDetail on Album {
}
}

mutation addAlbum($album: AddAlbumInput!) {
addAlbum(input: $album) {
fragment TagBase on Tag {
id
name
type
createdAt
updatedAt
}

mutation addAlbum($album: AddAlbumInput!, $commit: Boolean) {
addAlbum(input: $album, commit: $commit) {
...AlbumDetail
}
}
17 changes: 16 additions & 1 deletion anni-metadata/schemas/annim.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ type MetadataMutation {
"""
Add the metatada of a full album to annim.
"""
addAlbum(input: AddAlbumInput!): Album!
addAlbum(input: AddAlbumInput!, commit: Boolean): Album!
"""
Update basic album information.
Use this method to update basic album information such as title, artist and others.
Expand Down Expand Up @@ -262,6 +262,7 @@ enum MetadataOrganizeLevel {
type MetadataQuery {
album(albumId: UUID!): Album
albums(by: AlbumsBy!, after: String, first: Int): AlbumConnection!
tracks(keyword: String!): [TrackSearchResult!]!
tag(tagName: String!, tagType: TagType): [Tag!]!
}

Expand Down Expand Up @@ -338,6 +339,20 @@ type Track {
updatedAt: DateTime!
}

type TrackSearchResult {
"""
Return the search score of the track.
"""
score: Float!
"""
Return a `TrackIdentifier` string which represents the track.
"""
identifier: String!
album: Album
disc: Disc
track: Track
}

enum TrackType {
NORMAL
INSTRUMENTAL
Expand Down
2 changes: 2 additions & 0 deletions anni-metadata/src/annim/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl AnnimClient {
pub async fn add_album(
&self,
album: &model::Album,
commit: bool,
) -> anyhow::Result<query::album::AlbumFragment> {
let discs: Vec<_> = album.iter().collect();
let input = mutation::add_album::AddAlbumInput {
Expand Down Expand Up @@ -82,6 +83,7 @@ impl AnnimClient {
let query =
mutation::add_album::AddAlbumMutation::build(mutation::add_album::AddAlbumVariables {
album: input,
commit: Some(commit),
});
let response = self.client.post(&self.endpoint).run_graphql(query).await?;
if let Some(errors) = response.errors {
Expand Down
3 changes: 2 additions & 1 deletion anni-metadata/src/annim/mutation/add_album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ use crate::annim::{schema, Json, Uuid};
#[derive(cynic::QueryVariables, Debug)]
pub struct AddAlbumVariables<'a> {
pub album: AddAlbumInput<'a>,
pub commit: Option<bool>,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "MetadataMutation", variables = "AddAlbumVariables")]
pub struct AddAlbumMutation {
#[arguments(input: $album)]
#[arguments(input: $album, commit: $commit)]
pub add_album: AlbumFragment,
}

Expand Down
16 changes: 14 additions & 2 deletions anni/src/subcommands/repo/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,20 @@ async fn repo_migrate(me: RepoMigrateAction, manager: RepositoryManager) -> anyh

let mut albums = HashMap::new();
log::info!("Start inserting albums...");
for album in repo.albums_iter() {
let annim_album = client.add_album(album).await?;
let mut albums_iter = repo.albums_iter();
let last = albums_iter.next(); // read the first album for further commit

for album in albums_iter {
let annim_album = client.add_album(album, false).await?;
log::info!(
"Inserted album {}, id = {}",
annim_album.title,
annim_album.id.inner()
);
albums.insert(album.album_id, annim_album);
}
if let Some(album) = last {
let annim_album = client.add_album(album, true).await?;
log::info!(
"Inserted album {}, id = {}",
annim_album.title,
Expand Down
2 changes: 1 addition & 1 deletion anni/src/subcommands/workspace/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn handle_workspace_add(me: WorkspaceAddAction) -> anyhow::Result<()> {
}
anni_workspace::config::WorkspaceMetadata::Remote { endpoint, token } => {
let client = AnnimClient::new(endpoint, token.as_deref());
client.add_album(&album).await?;
client.add_album(&album, true).await?;
}
}
}
Expand Down

0 comments on commit 379bdfb

Please sign in to comment.