mirror of
https://github.com/modrinth/code.git
synced 2026-08-27 01:54:47 +00:00
perf: Attribution route perf improvements (#6489)
* Attribution route perf improvements * fix clippy * clear exemptions when user attempts to scan their file * Increase Redis TTL/refresh time
This commit is contained in:
@@ -102,6 +102,7 @@ pub async fn scan_all_files(
|
||||
file_id,
|
||||
&overrides,
|
||||
&resolved,
|
||||
redis,
|
||||
&mut txn,
|
||||
)
|
||||
.await
|
||||
@@ -164,7 +165,7 @@ pub async fn scan_file(
|
||||
})?;
|
||||
|
||||
persist_attribution_results(
|
||||
project_id, file_id, &overrides, &resolved, txn,
|
||||
project_id, file_id, &overrides, &resolved, redis, txn,
|
||||
)
|
||||
.await
|
||||
.wrap_err_with(|| {
|
||||
@@ -303,6 +304,7 @@ async fn persist_attribution_results(
|
||||
file_id: DBFileId,
|
||||
overrides: &[OverrideFile],
|
||||
resolved: &HashMap<String, OverrideResolution>,
|
||||
redis: &RedisPool,
|
||||
txn: &mut PgTransaction<'_>,
|
||||
) -> Result<()> {
|
||||
let all_sha1s: Vec<Vec<u8>> = overrides
|
||||
@@ -552,6 +554,22 @@ async fn persist_attribution_results(
|
||||
.wrap_err("inserting override file sources")?;
|
||||
}
|
||||
|
||||
let version_id = sqlx::query_scalar!(
|
||||
r#"
|
||||
select version_id as "version_id: DBVersionId"
|
||||
from files
|
||||
where id = $1
|
||||
"#,
|
||||
file_id as DBFileId,
|
||||
)
|
||||
.fetch_one(&mut *txn)
|
||||
.await
|
||||
.wrap_err("fetching scanned file version")?;
|
||||
|
||||
DBVersion::clear_cache_ids(&[version_id], redis)
|
||||
.await
|
||||
.wrap_err("clearing version cache after attribution scan")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -242,7 +242,8 @@ impl AutomatedModerationQueue {
|
||||
for project in projects {
|
||||
async {
|
||||
let project =
|
||||
database::DBProject::get_id((project).into(), &pool, &redis).await?;
|
||||
database::DBProject::get_id((project).into(), &*ro_pool, &redis)
|
||||
.await?;
|
||||
|
||||
if let Some(project) = project {
|
||||
let res = async {
|
||||
@@ -282,7 +283,7 @@ impl AutomatedModerationQueue {
|
||||
}
|
||||
|
||||
let versions =
|
||||
database::DBVersion::get_many(&project.versions, &pool, &redis)
|
||||
database::DBVersion::get_many(&project.versions, &*ro_pool, &redis)
|
||||
.await?
|
||||
.into_iter()
|
||||
// we only support modpacks at this time
|
||||
@@ -374,7 +375,7 @@ impl AutomatedModerationQueue {
|
||||
let versions_data = filter_visible_versions(
|
||||
database::models::DBVersion::get_many(
|
||||
&version_ids,
|
||||
&pool,
|
||||
&*ro_pool,
|
||||
&redis,
|
||||
)
|
||||
.await?,
|
||||
|
||||
Reference in New Issue
Block a user