Skip to content

Commit

Permalink
Cleanup data (#817)
Browse files Browse the repository at this point in the history
* feat(backend): stub new cleanup method

* refactor(backend): remove pub modifiers from funcs

* chore(frontend): remove useless comma

* feat(backend): call disable useless data in media job

* feat(backend): move func call to somewhere eles

* feat(backend): cleanup old useless data

* fix(backend): add `debug` logging

* build(backend): bump version

* chore(frontend): change wording
  • Loading branch information
IgnisDa committed May 6, 2024
1 parent 0c4d39b commit 8ffe94a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "5.2.2"
version = "5.2.3"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-3.0"
Expand Down
85 changes: 60 additions & 25 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,7 @@ impl MiscellaneousService {
Ok(ProgressUpdateResultUnion::Ok(IdObject { id }))
}

pub async fn deploy_bulk_progress_update(
async fn deploy_bulk_progress_update(
&self,
user_id: i32,
input: Vec<ProgressUpdateInput>,
Expand Down Expand Up @@ -2777,7 +2777,7 @@ impl MiscellaneousService {
Ok(true)
}

pub async fn cleanup_user_and_metadata_association(&self) -> Result<()> {
async fn cleanup_user_and_metadata_association(&self) -> Result<()> {
let all_users = User::find()
.select_only()
.column(user::Column::Id)
Expand Down Expand Up @@ -2897,7 +2897,7 @@ impl MiscellaneousService {
Ok(())
}

pub async fn update_media(
async fn update_media(
&self,
metadata_id: i32,
input: MediaDetails,
Expand Down Expand Up @@ -3109,7 +3109,7 @@ impl MiscellaneousService {
Ok(notifications)
}

pub async fn associate_person_with_metadata(
async fn associate_person_with_metadata(
&self,
metadata_id: i32,
person: PartialMetadataPerson,
Expand Down Expand Up @@ -3395,7 +3395,7 @@ impl MiscellaneousService {
Ok(())
}

pub async fn deploy_update_metadata_job(&self, metadata_id: i32) -> Result<String> {
async fn deploy_update_metadata_job(&self, metadata_id: i32) -> Result<String> {
let metadata = Metadata::find_by_id(metadata_id)
.one(&self.db)
.await
Expand All @@ -3409,7 +3409,7 @@ impl MiscellaneousService {
Ok(job_id.to_string())
}

pub async fn deploy_update_person_job(&self, person_id: i32) -> Result<String> {
async fn deploy_update_person_job(&self, person_id: i32) -> Result<String> {
let person = Person::find_by_id(person_id)
.one(&self.db)
.await
Expand All @@ -3423,12 +3423,7 @@ impl MiscellaneousService {
Ok(job_id.to_string())
}

pub async fn merge_metadata(
&self,
user_id: i32,
merge_from: i32,
merge_into: i32,
) -> Result<bool> {
async fn merge_metadata(&self, user_id: i32, merge_from: i32, merge_into: i32) -> Result<bool> {
for old_seen in Seen::find()
.filter(seen::Column::MetadataId.eq(merge_from))
.filter(seen::Column::UserId.eq(user_id))
Expand Down Expand Up @@ -4376,7 +4371,7 @@ impl MiscellaneousService {
})
}

pub async fn delete_review(&self, user_id: i32, review_id: i32) -> Result<bool> {
async fn delete_review(&self, user_id: i32, review_id: i32) -> Result<bool> {
let review = Review::find()
.filter(review::Column::Id.eq(review_id))
.one(&self.db)
Expand Down Expand Up @@ -4453,7 +4448,7 @@ impl MiscellaneousService {
}
}

pub async fn delete_collection(&self, user_id: i32, name: &str) -> Result<bool> {
async fn delete_collection(&self, user_id: i32, name: &str) -> Result<bool> {
if DefaultCollection::iter().any(|col_name| col_name.to_string() == name) {
return Err(Error::new("Can not delete a default collection".to_owned()));
}
Expand Down Expand Up @@ -4513,7 +4508,7 @@ impl MiscellaneousService {
Ok(IdObject { id: collect.id })
}

pub async fn delete_seen_item(&self, user_id: i32, seen_id: i32) -> Result<IdObject> {
async fn delete_seen_item(&self, user_id: i32, seen_id: i32) -> Result<IdObject> {
let seen_item = Seen::find_by_id(seen_id).one(&self.db).await.unwrap();
if let Some(si) = seen_item {
let (ssn, sen) = match &si.show_extra_information {
Expand Down Expand Up @@ -5033,7 +5028,7 @@ impl MiscellaneousService {
Ok(IdObject { id: user_obj.id })
}

pub async fn regenerate_user_summaries(&self) -> Result<()> {
async fn regenerate_user_summaries(&self) -> Result<()> {
let all_users = User::find()
.select_only()
.column(user::Column::Id)
Expand Down Expand Up @@ -5998,7 +5993,7 @@ impl MiscellaneousService {
Ok(())
}

pub async fn after_media_seen_tasks(&self, seen: seen::Model) -> Result<()> {
async fn after_media_seen_tasks(&self, seen: seen::Model) -> Result<()> {
let add_entity_to_collection = |collection_name: &str| {
self.add_entity_to_collection(
seen.user_id,
Expand Down Expand Up @@ -6124,11 +6119,7 @@ impl MiscellaneousService {
}

#[tracing::instrument(skip(self, msg))]
pub async fn send_notifications_to_user_platforms(
&self,
user_id: i32,
msg: &str,
) -> Result<bool> {
async fn send_notifications_to_user_platforms(&self, user_id: i32, msg: &str) -> Result<bool> {
let user_details = user_by_id(&self.db, user_id).await?;
let mut success = true;
if user_details.preferences.notifications.enabled {
Expand Down Expand Up @@ -6185,7 +6176,7 @@ impl MiscellaneousService {
Ok(())
}

pub async fn send_media_state_changed_notification_for_user(
async fn send_media_state_changed_notification_for_user(
&self,
user_id: i32,
notification: &(String, MediaStateChanged),
Expand All @@ -6200,7 +6191,7 @@ impl MiscellaneousService {
Ok(())
}

pub async fn genres_list(&self, input: SearchInput) -> Result<SearchResults<GenreListItem>> {
async fn genres_list(&self, input: SearchInput) -> Result<SearchResults<GenreListItem>> {
let page: u64 = input.page.unwrap_or(1).try_into().unwrap();
let num_items = "num_items";
let query = Genre::find()
Expand Down Expand Up @@ -6245,7 +6236,7 @@ impl MiscellaneousService {
})
}

pub async fn metadata_groups_list(
async fn metadata_groups_list(
&self,
user_id: i32,
input: SearchInput,
Expand Down Expand Up @@ -7302,11 +7293,55 @@ GROUP BY m.id;
}
}

pub async fn remove_useless_data(&self) -> Result<()> {
let mut metadata_stream = Metadata::find()
.select_only()
.column(metadata::Column::Id)
.left_join(UserToEntity)
.filter(user_to_entity::Column::MetadataId.is_null())
.into_tuple::<i32>()
.stream(&self.db)
.await?;
while let Some(meta) = metadata_stream.try_next().await? {
tracing::debug!("Removing metadata id = {:#?}", meta);
Metadata::delete_by_id(meta).exec(&self.db).await?;
}
let mut people_stream = Person::find()
.select_only()
.column(person::Column::Id)
.left_join(UserToEntity)
.filter(user_to_entity::Column::PersonId.is_null())
.into_tuple::<i32>()
.stream(&self.db)
.await?;
while let Some(person) = people_stream.try_next().await? {
tracing::debug!("Removing person id = {:#?}", person);
Person::delete_by_id(person).exec(&self.db).await?;
}
let mut metadata_group_stream = MetadataGroup::find()
.select_only()
.column(metadata_group::Column::Id)
.left_join(UserToEntity)
.filter(user_to_entity::Column::MetadataGroupId.is_null())
.into_tuple::<i32>()
.stream(&self.db)
.await?;
while let Some(meta_group) = metadata_group_stream.try_next().await? {
tracing::debug!("Removing metadata group id = {:#?}", meta_group);
MetadataGroup::delete_by_id(meta_group)
.exec(&self.db)
.await?;
}
Ok(())
}

pub async fn perform_user_jobs(&self) -> Result<()> {
tracing::trace!("Cleaning up user and metadata association");
self.cleanup_user_and_metadata_association().await?;
tracing::trace!("Removing old user summaries and regenerating them");
self.regenerate_user_summaries().await?;
tracing::trace!("Removing useless data");
self.remove_useless_data().await?;
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export default function Page() {
))}
</ApplicationGrid>
) : (
<Text>You have not added any media to this collection</Text>
<Text>You have not added anything this collection</Text>
)}
{loaderData.contents.details ? (
<Center>
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/app/routes/_dashboard.collections.list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const DisplayCollection = (props: {
<Title order={4}>{props.collection.name}</Title>
</Anchor>
<Text c="dimmed" size="xs">
{props.collection.numItems} items,{" "}
{props.collection.numItems} items
</Text>
</Flex>
{props.collection.description ? (
Expand Down

0 comments on commit 8ffe94a

Please sign in to comment.