Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
delete revs
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Oct 6, 2023
1 parent 79df302 commit a2ad467
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 43 deletions.
16 changes: 9 additions & 7 deletions src/database/models/organization_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,15 @@ impl Organization {
title: Option<String>,
redis: &RedisPool,
) -> Result<(), super::DatabaseError> {
redis.delete(ORGANIZATIONS_NAMESPACE, id.0).await?;
if let Some(title) = title {
redis
.delete(ORGANIZATIONS_TITLES_NAMESPACE, title.to_lowercase())
.await?;
}

redis
.delete_many([
(ORGANIZATIONS_NAMESPACE, Some(id.0.to_string())),
(
ORGANIZATIONS_TITLES_NAMESPACE,
title.map(|x| x.to_lowercase()),
),
])
.await?;
Ok(())
}
}
12 changes: 6 additions & 6 deletions src/database/models/pat_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ impl PersonalAccessToken {
return Ok(());
}

for (id, token, user_id) in clear_pats {
redis
.delete_many([
redis
.delete_many(clear_pats.into_iter().flat_map(|(id, token, user_id)| {
[
(PATS_NAMESPACE, id.map(|i| i.0.to_string())),
(PATS_TOKENS_NAMESPACE, token),
(PATS_USERS_NAMESPACE, user_id.map(|i| i.0.to_string())),
])
.await?;
}
]
}))
.await?;

Ok(())
}
Expand Down
23 changes: 13 additions & 10 deletions src/database/models/session_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,19 @@ impl Session {
return Ok(());
}

for (id, session, user_id) in clear_sessions {
redis
.delete_many([
(SESSIONS_NAMESPACE, id.map(|i| i.0.to_string())),
(SESSIONS_IDS_NAMESPACE, session),
(SESSIONS_USERS_NAMESPACE, user_id.map(|i| i.0.to_string())),
])
.await?;
}

redis
.delete_many(
clear_sessions
.into_iter()
.flat_map(|(id, session, user_id)| {
[
(SESSIONS_NAMESPACE, id.map(|i| i.0.to_string())),
(SESSIONS_IDS_NAMESPACE, session),
(SESSIONS_USERS_NAMESPACE, user_id.map(|i| i.0.to_string())),
]
}),
)
.await?;
Ok(())
}

Expand Down
21 changes: 11 additions & 10 deletions src/database/models/user_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,17 @@ impl User {
user_ids: &[(UserId, Option<String>)],
redis: &RedisPool,
) -> Result<(), DatabaseError> {
for (id, username) in user_ids {
redis.delete(USERS_NAMESPACE, id.0).await?;

if let Some(username) = username {
redis
.delete(USER_USERNAMES_NAMESPACE, username.to_lowercase())
.await?;
}
}

redis
.delete_many(user_ids.into_iter().flat_map(|(id, username)| {

Check warning on line 355 in src/database/models/user_item.rs

View workflow job for this annotation

GitHub Actions / clippy

this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice`

warning: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` --> src/database/models/user_item.rs:355:35 | 355 | .delete_many(user_ids.into_iter().flat_map(|(id, username)| { | ^^^^^^^^^ help: call directly: `iter` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref = note: `#[warn(clippy::into_iter_on_ref)]` on by default
[
(USERS_NAMESPACE, Some(id.0.to_string())),
(
USER_USERNAMES_NAMESPACE,
username.clone().map(|i| i.to_lowercase()),
),
]
}))
.await?;
Ok(())
}

Expand Down
22 changes: 12 additions & 10 deletions src/database/models/version_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::collections::HashMap;
use std::iter;

const VERSIONS_NAMESPACE: &str = "versions";
const VERSION_FILES_NAMESPACE: &str = "versions_files";
Expand Down Expand Up @@ -736,16 +737,17 @@ impl Version {
version: &QueryVersion,
redis: &RedisPool,
) -> Result<(), DatabaseError> {
redis.delete(VERSIONS_NAMESPACE, version.inner.id.0).await?;

for file in &version.files {
for (algo, hash) in &file.hashes {
redis
.delete(VERSION_FILES_NAMESPACE, format!("{}_{}", algo, hash))
.await?;
}
}

redis
.delete_many(
iter::once((VERSIONS_NAMESPACE, Some(version.inner.id.0.to_string()))).chain(
version.files.iter().flat_map(|file| {
file.hashes.iter().map(|(algo, hash)| {
(VERSION_FILES_NAMESPACE, Some(format!("{}_{}", algo, hash)))
})
}),
),
)
.await?;
Ok(())
}
}
Expand Down

0 comments on commit a2ad467

Please sign in to comment.