Skip to content

Commit

Permalink
Download group details as a background job (#372)
Browse files Browse the repository at this point in the history
* fix(backend): drop index on correct table

* fix(backend): make migration text better

* chore(backend): log name and job time in ms

* fix(backend): make exports much smaller

* style(frontend): remove useless braces

* fix(backend): change name of var

* feat(backend): add trait to get group details

* fix(backend): set correct part index for media items

* fix(frontend): show loading icon for creating auth token

* docs: make language clearer

* chore(backend): add comments to export related structures

* chore(backend): add new field to get just group identifier

* refactor(backend): do not return group details from providers

* build(backend): bump version

* refactor(backend): move group details as a trait parameter

* build(backend): add boilermate deps

* scaffold(backend): job to associate group with metadata

* chore(backend): code to for handling exisiting grps

* refactor(backend): remove useless field

* feat(backend): complete associating groups with metadata

* refactor(backend): remove useless model
  • Loading branch information
IgnisDa authored Sep 28, 2023
1 parent 5a4cc62 commit 85fdba9
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 270 deletions.
14 changes: 13 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "2.19.2"
version = "2.19.3"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-V3"
Expand All @@ -27,6 +27,7 @@ axum = { version = "0.6.20", features = ["macros", "multipart"] }
axum-extra = { version = "0.8.0", default-features = false, features = [
"cookie",
] }
boilermates = "0.3.0"
chrono = "0.4.31"
convert_case = "0.6.0"
const-str = "0.5.6"
Expand Down
18 changes: 16 additions & 2 deletions apps/backend/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use std::{sync::Arc, time::Instant};
use apalis::prelude::{Job, JobContext, JobError};
use sea_orm::prelude::DateTimeUtc;
use serde::{Deserialize, Serialize};
use strum::Display;

use crate::{
entities::{metadata, seen},
fitness::resolver::ExerciseService,
importer::{DeployImportJobInput, ImporterService},
migrator::{MetadataLot, MetadataSource},
miscellaneous::resolver::MiscellaneousService,
models::{fitness::Exercise, media::PartialMetadataPerson},
};
Expand Down Expand Up @@ -82,7 +84,7 @@ pub async fn yank_integrations_data(

// Application Jobs

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize, Display)]
pub enum ApplicationJob {
ImportMedia(i32, DeployImportJobInput),
UserCreated(i32),
Expand All @@ -92,6 +94,7 @@ pub enum ApplicationJob {
AfterMediaSeen(seen::Model),
RecalculateCalendarEvents,
AssociatePersonWithMetadata(i32, PartialMetadataPerson, usize),
AssociateGroupWithMetadata(MetadataLot, MetadataSource, String),
}

impl Job for ApplicationJob {
Expand All @@ -102,6 +105,7 @@ pub async fn perform_application_job(
information: ApplicationJob,
ctx: JobContext,
) -> Result<(), JobError> {
let name = information.to_string();
let importer_service = ctx.data::<Arc<ImporterService>>().unwrap();
let misc_service = ctx.data::<Arc<MiscellaneousService>>().unwrap();
let exercise_service = ctx.data::<Arc<ExerciseService>>().unwrap();
Expand Down Expand Up @@ -153,8 +157,18 @@ pub async fn perform_application_job(
.await
.unwrap();
}
ApplicationJob::AssociateGroupWithMetadata(lot, source, group_identifier) => {
misc_service
.associate_group_with_metadata(lot, source, group_identifier)
.await
.unwrap();
}
};
let end = Instant::now();
tracing::trace!("Job completed, took {}s", (end - start).as_secs());
tracing::trace!(
"Job {:#?} completed in {}ms",
name,
(end - start).as_millis()
);
Ok(())
}
3 changes: 3 additions & 0 deletions apps/backend/src/entities/metadata_group.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use async_graphql::SimpleObject;
use boilermates::boilermates;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};

Expand All @@ -12,7 +13,9 @@ use crate::{
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, SimpleObject)]
#[sea_orm(table_name = "metadata_group")]
#[graphql(name = "MetadataGroup")]
#[boilermates("MetadataGroupWithoutId")]
pub struct Model {
#[boilermates(not_in("MetadataGroupWithoutId"))]
#[sea_orm(primary_key)]
pub id: i32,
pub parts: i32,
Expand Down
8 changes: 8 additions & 0 deletions apps/backend/src/entities/partial_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use async_graphql::SimpleObject;
use async_trait::async_trait;
use boilermates::boilermates;
use sea_orm::{entity::prelude::*, ActiveValue};
use serde::{Deserialize, Serialize};

Expand All @@ -12,10 +13,16 @@ use crate::{

use super::metadata;

#[boilermates("PartialMetadataWithoutId")]
#[boilermates(attr_for(
"PartialMetadataWithoutId",
"#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Hash)]"
))]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize, SimpleObject)]
#[sea_orm(table_name = "partial_metadata")]
#[graphql(name = "PartialMetadata")]
pub struct Model {
#[boilermates(not_in("PartialMetadataWithoutId"))]
#[sea_orm(primary_key)]
#[graphql(skip)]
pub id: i32,
Expand All @@ -24,6 +31,7 @@ pub struct Model {
pub image: Option<String>,
pub lot: MetadataLot,
pub source: MetadataSource,
#[boilermates(not_in("PartialMetadataWithoutId"))]
pub metadata_id: Option<i32>,
}

Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/entities/user_measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
use async_graphql::{InputObject, SimpleObject};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use specta::Type;

use crate::models::fitness::UserMeasurementStats;

/// An export of a measurement taken at a point in time.
#[skip_serializing_none]
#[derive(
Clone,
Debug,
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/importer/goodreads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub async fn import(input: DeployGoodreadsImportInput) -> Result<ImportResult> {
publish_date: None,
genres: vec![],
suggestions: vec![],
groups: vec![],
group_identifiers: vec![],
is_nsfw: None,
people: vec![],
s3_images: vec![],
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/importer/media_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub async fn import(input: DeployMediaTrackerImportInput) -> Result<ImportResult
publish_year: None,
publish_date: None,
suggestions: vec![],
groups: vec![],
group_identifiers: vec![],
is_nsfw: None,
people: vec![],
s3_images: vec![],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ pub struct Migration;
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_index(Index::drop().name(PERSON_IDENTIFIER_UNIQUE_KEY).to_owned())
.drop_index(
Index::drop()
.table(Person::Table)
.name(PERSON_IDENTIFIER_UNIQUE_KEY)
.to_owned(),
)
.await?;
manager
.create_index(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl MigrationTrait for Migration {
let message = format!("
This migration will delete all old creators (changes introduced in `v2.19.0`) and associated reviews.
You have reviews for {count} creator(s).
Please downgrade to the `v2.19.0`, follow instructions at https://github.com/IgnisDa/ryot/releases/tag/v2.19.0 to migrate this data, and then upgrade again.
Please downgrade to `v2.19.0`, follow instructions at https://github.com/IgnisDa/ryot/releases/tag/v2.19.0 to migrate this data, and then upgrade again.
If you want to skip this check, please set the environment variable `{var_name}=1`.");
tracing::info!(message);
Expand Down
Loading

0 comments on commit 85fdba9

Please sign in to comment.