Skip to content

Commit bc917d3

Browse files
committed
fix(mods): touch created_at when accepting first version
1 parent b8462b4 commit bc917d3

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/database/repository/mods.rs

+17
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,20 @@ pub async fn update_with_json_moved(
297297

298298
Ok(the_mod)
299299
}
300+
301+
/// Used when first version goes from pending to accepted.
302+
/// Makes it so versions that stay a lot in pending appear at the top of the newly created lists
303+
pub async fn touch_created_at(id: &str, conn: &mut PgConnection) -> Result<(), ApiError> {
304+
sqlx::query!(
305+
"UPDATE mods
306+
SET updated_at = NOW()
307+
WHERE id = $1",
308+
id
309+
)
310+
.execute(conn)
311+
.await
312+
.inspect_err(|e| log::error!("Failed to touch updated_at for mod {}: {}", id, e))
313+
.or(Err(ApiError::DbError))?;
314+
315+
Ok(())
316+
}

src/endpoints/mod_versions.rs

+5
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ pub async fn update_version(
460460
if old_status == ModVersionStatusEnum::Pending
461461
&& version.status == ModVersionStatusEnum::Accepted
462462
{
463+
if approved_count == 0 {
464+
// Used to push new mods to the top of the "Recently created" list
465+
mods::touch_created_at(&the_mod.id, &mut tx).await?;
466+
}
467+
463468
let bytes = mod_zip::download_mod_hash_comp(
464469
&version.download_link,
465470
&version.hash,

0 commit comments

Comments
 (0)