Skip to content

Commit 8ffe94a

Browse files
authored
Cleanup data (#817)
* 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
1 parent 0c4d39b commit 8ffe94a

File tree

5 files changed

+64
-29
lines changed

5 files changed

+64
-29
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/backend/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ryot"
3-
version = "5.2.2"
3+
version = "5.2.3"
44
edition = "2021"
55
repository = "https://github.com/IgnisDa/ryot"
66
license = "GPL-3.0"

apps/backend/src/miscellaneous/resolver.rs

+60-25
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@ impl MiscellaneousService {
26862686
Ok(ProgressUpdateResultUnion::Ok(IdObject { id }))
26872687
}
26882688

2689-
pub async fn deploy_bulk_progress_update(
2689+
async fn deploy_bulk_progress_update(
26902690
&self,
26912691
user_id: i32,
26922692
input: Vec<ProgressUpdateInput>,
@@ -2777,7 +2777,7 @@ impl MiscellaneousService {
27772777
Ok(true)
27782778
}
27792779

2780-
pub async fn cleanup_user_and_metadata_association(&self) -> Result<()> {
2780+
async fn cleanup_user_and_metadata_association(&self) -> Result<()> {
27812781
let all_users = User::find()
27822782
.select_only()
27832783
.column(user::Column::Id)
@@ -2897,7 +2897,7 @@ impl MiscellaneousService {
28972897
Ok(())
28982898
}
28992899

2900-
pub async fn update_media(
2900+
async fn update_media(
29012901
&self,
29022902
metadata_id: i32,
29032903
input: MediaDetails,
@@ -3109,7 +3109,7 @@ impl MiscellaneousService {
31093109
Ok(notifications)
31103110
}
31113111

3112-
pub async fn associate_person_with_metadata(
3112+
async fn associate_person_with_metadata(
31133113
&self,
31143114
metadata_id: i32,
31153115
person: PartialMetadataPerson,
@@ -3395,7 +3395,7 @@ impl MiscellaneousService {
33953395
Ok(())
33963396
}
33973397

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

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

3426-
pub async fn merge_metadata(
3427-
&self,
3428-
user_id: i32,
3429-
merge_from: i32,
3430-
merge_into: i32,
3431-
) -> Result<bool> {
3426+
async fn merge_metadata(&self, user_id: i32, merge_from: i32, merge_into: i32) -> Result<bool> {
34323427
for old_seen in Seen::find()
34333428
.filter(seen::Column::MetadataId.eq(merge_from))
34343429
.filter(seen::Column::UserId.eq(user_id))
@@ -4376,7 +4371,7 @@ impl MiscellaneousService {
43764371
})
43774372
}
43784373

4379-
pub async fn delete_review(&self, user_id: i32, review_id: i32) -> Result<bool> {
4374+
async fn delete_review(&self, user_id: i32, review_id: i32) -> Result<bool> {
43804375
let review = Review::find()
43814376
.filter(review::Column::Id.eq(review_id))
43824377
.one(&self.db)
@@ -4453,7 +4448,7 @@ impl MiscellaneousService {
44534448
}
44544449
}
44554450

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

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

5036-
pub async fn regenerate_user_summaries(&self) -> Result<()> {
5031+
async fn regenerate_user_summaries(&self) -> Result<()> {
50375032
let all_users = User::find()
50385033
.select_only()
50395034
.column(user::Column::Id)
@@ -5998,7 +5993,7 @@ impl MiscellaneousService {
59985993
Ok(())
59995994
}
60005995

6001-
pub async fn after_media_seen_tasks(&self, seen: seen::Model) -> Result<()> {
5996+
async fn after_media_seen_tasks(&self, seen: seen::Model) -> Result<()> {
60025997
let add_entity_to_collection = |collection_name: &str| {
60035998
self.add_entity_to_collection(
60045999
seen.user_id,
@@ -6124,11 +6119,7 @@ impl MiscellaneousService {
61246119
}
61256120

61266121
#[tracing::instrument(skip(self, msg))]
6127-
pub async fn send_notifications_to_user_platforms(
6128-
&self,
6129-
user_id: i32,
6130-
msg: &str,
6131-
) -> Result<bool> {
6122+
async fn send_notifications_to_user_platforms(&self, user_id: i32, msg: &str) -> Result<bool> {
61326123
let user_details = user_by_id(&self.db, user_id).await?;
61336124
let mut success = true;
61346125
if user_details.preferences.notifications.enabled {
@@ -6185,7 +6176,7 @@ impl MiscellaneousService {
61856176
Ok(())
61866177
}
61876178

6188-
pub async fn send_media_state_changed_notification_for_user(
6179+
async fn send_media_state_changed_notification_for_user(
61896180
&self,
61906181
user_id: i32,
61916182
notification: &(String, MediaStateChanged),
@@ -6200,7 +6191,7 @@ impl MiscellaneousService {
62006191
Ok(())
62016192
}
62026193

6203-
pub async fn genres_list(&self, input: SearchInput) -> Result<SearchResults<GenreListItem>> {
6194+
async fn genres_list(&self, input: SearchInput) -> Result<SearchResults<GenreListItem>> {
62046195
let page: u64 = input.page.unwrap_or(1).try_into().unwrap();
62056196
let num_items = "num_items";
62066197
let query = Genre::find()
@@ -6245,7 +6236,7 @@ impl MiscellaneousService {
62456236
})
62466237
}
62476238

6248-
pub async fn metadata_groups_list(
6239+
async fn metadata_groups_list(
62496240
&self,
62506241
user_id: i32,
62516242
input: SearchInput,
@@ -7302,11 +7293,55 @@ GROUP BY m.id;
73027293
}
73037294
}
73047295

7296+
pub async fn remove_useless_data(&self) -> Result<()> {
7297+
let mut metadata_stream = Metadata::find()
7298+
.select_only()
7299+
.column(metadata::Column::Id)
7300+
.left_join(UserToEntity)
7301+
.filter(user_to_entity::Column::MetadataId.is_null())
7302+
.into_tuple::<i32>()
7303+
.stream(&self.db)
7304+
.await?;
7305+
while let Some(meta) = metadata_stream.try_next().await? {
7306+
tracing::debug!("Removing metadata id = {:#?}", meta);
7307+
Metadata::delete_by_id(meta).exec(&self.db).await?;
7308+
}
7309+
let mut people_stream = Person::find()
7310+
.select_only()
7311+
.column(person::Column::Id)
7312+
.left_join(UserToEntity)
7313+
.filter(user_to_entity::Column::PersonId.is_null())
7314+
.into_tuple::<i32>()
7315+
.stream(&self.db)
7316+
.await?;
7317+
while let Some(person) = people_stream.try_next().await? {
7318+
tracing::debug!("Removing person id = {:#?}", person);
7319+
Person::delete_by_id(person).exec(&self.db).await?;
7320+
}
7321+
let mut metadata_group_stream = MetadataGroup::find()
7322+
.select_only()
7323+
.column(metadata_group::Column::Id)
7324+
.left_join(UserToEntity)
7325+
.filter(user_to_entity::Column::MetadataGroupId.is_null())
7326+
.into_tuple::<i32>()
7327+
.stream(&self.db)
7328+
.await?;
7329+
while let Some(meta_group) = metadata_group_stream.try_next().await? {
7330+
tracing::debug!("Removing metadata group id = {:#?}", meta_group);
7331+
MetadataGroup::delete_by_id(meta_group)
7332+
.exec(&self.db)
7333+
.await?;
7334+
}
7335+
Ok(())
7336+
}
7337+
73057338
pub async fn perform_user_jobs(&self) -> Result<()> {
73067339
tracing::trace!("Cleaning up user and metadata association");
73077340
self.cleanup_user_and_metadata_association().await?;
73087341
tracing::trace!("Removing old user summaries and regenerating them");
73097342
self.regenerate_user_summaries().await?;
7343+
tracing::trace!("Removing useless data");
7344+
self.remove_useless_data().await?;
73107345
Ok(())
73117346
}
73127347

apps/frontend/app/routes/_dashboard.collections.$id._index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export default function Page() {
304304
))}
305305
</ApplicationGrid>
306306
) : (
307-
<Text>You have not added any media to this collection</Text>
307+
<Text>You have not added anything this collection</Text>
308308
)}
309309
{loaderData.contents.details ? (
310310
<Center>

apps/frontend/app/routes/_dashboard.collections.list.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const DisplayCollection = (props: {
248248
<Title order={4}>{props.collection.name}</Title>
249249
</Anchor>
250250
<Text c="dimmed" size="xs">
251-
{props.collection.numItems} items,{" "}
251+
{props.collection.numItems} items
252252
</Text>
253253
</Flex>
254254
{props.collection.description ? (

0 commit comments

Comments
 (0)