Fix updated field including deleted versions (#3643)

* Fix `updated` field including deleted versions

Four years ago, I created issue modrinth/labrinth#200. Today, while it adorns a different name (modrinth/code#2766), the issue remains the same. In celebration of Modrinth's oldest bug report, here is a fix.

Instead of having a separate `updated` field, it simply pulls the publish date of the most recent version. This should also allow the `updated` column on the `mods` table to be dropped at a later date, but I would rather get confirmation that it works before we go ahead with that.

Fixes #2766

* Update apps/labrinth/src/database/models/project_item.rs

Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
Signed-off-by: Emma Alexia <wafflecoffee7@gmail.com>

---------

Signed-off-by: Emma Alexia <wafflecoffee7@gmail.com>
Co-authored-by: Alejandro González <7822554+AlexTMjugador@users.noreply.github.com>
This commit is contained in:
Emma Alexia
2025-05-12 14:19:30 -04:00
committed by GitHub
parent 9a6390bb4d
commit 863bf62f8d
2 changed files with 23 additions and 31 deletions

View File

@@ -759,7 +759,7 @@ impl Project {
"
SELECT m.id id, m.name name, m.summary summary, m.downloads downloads, m.follows follows,
m.icon_url icon_url, m.raw_icon_url raw_icon_url, m.description description, m.published published,
m.updated updated, m.approved approved, m.queued, m.status status, m.requested_status requested_status,
m.approved approved, m.queued, m.status status, m.requested_status requested_status,
m.license_url license_url,
m.team_id team_id, m.organization_id organization_id, m.license license, m.slug slug, m.moderation_message moderation_message, m.moderation_message_body moderation_message_body,
m.webhook_sent, m.color,
@@ -786,7 +786,9 @@ impl Project {
games,
loader_loader_field_ids,
} = loaders_ptypes_games.remove(&project_id).map(|x|x.1).unwrap_or_default();
// Each version is a tuple of (VersionId, DateTime<Utc>)
let mut versions = versions.remove(&project_id).map(|x| x.1).unwrap_or_default();
versions.sort_by(|a, b| a.1.cmp(&b.1));
let mut gallery = mods_gallery.remove(&project_id).map(|x| x.1).unwrap_or_default();
let urls = links.remove(&project_id).map(|x| x.1).unwrap_or_default();
let version_fields = version_fields.remove(&project_id).map(|x| x.1).unwrap_or_default();
@@ -806,7 +808,7 @@ impl Project {
icon_url: m.icon_url.clone(),
raw_icon_url: m.raw_icon_url.clone(),
published: m.published,
updated: m.updated,
updated: versions.iter().map(|x| x.1).next_back().unwrap_or(m.published),
license_url: m.license_url.clone(),
status: ProjectStatus::from_string(
&m.status,
@@ -833,11 +835,7 @@ impl Project {
additional_categories: m.additional_categories.unwrap_or_default(),
project_types,
games,
versions: {
// Each version is a tuple of (VersionId, DateTime<Utc>)
versions.sort_by(|a, b| a.1.cmp(&b.1));
versions.into_iter().map(|x| x.0).collect()
},
versions: versions.into_iter().map(|x| x.0).collect(),
gallery_items: {
gallery.sort_by(|a, b| a.ordering.cmp(&b.ordering));
gallery