Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative follower counts cause whackiness #3185

Open
2 tasks done
realRobotix opened this issue Jan 24, 2025 · 3 comments
Open
2 tasks done

Negative follower counts cause whackiness #3185

realRobotix opened this issue Jan 24, 2025 · 3 comments
Labels
backend Relates to Modrinth Backend or API bug Something isn't working

Comments

@realRobotix
Copy link

Please confirm the following.

Describe the bug

Negative follower counts can be stored in the db causing all kinds of whackiness due to different types being used in different places and unsafe type conversion. Might be caused by the project being inherited but i wasn't yet able to further dig into that.
first discovered here

db uses integer

database/models/project_items.rs uses i32

models/v2/projects.rs uses u32 (unsafe conversion happens here)

models/v3/projects.rs uses u32 (and also here)

models/v2/search.rs uses i32

Steps to reproduce

  1. Go to https://modrinth.com/modpack/advanced-optimized-official
  2. Take a look at the follower count (u32::MAX)
  3. Go to https://modrinth.com/modpacks?s=follows&m=1&page=8040 or the last page with sort set to followers
  4. Take another look at the follower count (-1i32)

Expected behavior

No negative follower counts

Additional context

No response

@realRobotix realRobotix added backend Relates to Modrinth Backend or API bug Something isn't working labels Jan 24, 2025
@realRobotix
Copy link
Author

I'm also not too sure why followers are saved in two locations. I feel like the better approach would be just to use COUNT on the mod_follows table (maybe with some caching if it's too inefficient). https://github.com/modrinth/code/blob/main/apps/labrinth/src/routes/v3/projects.rs#L2211-L2229

@imheavi
Copy link

imheavi commented Jan 24, 2025

The database probably stores a follow count for each project, as well as the total follow count for an account, hence why there are too. Possible I'm wrong however.

@realRobotix
Copy link
Author

no, the follows relation is stored in the mod_follows table consisting of the user id and mod id. so far so good...
but there is also a follow count in the mod table which isn't being handled in the same way (e.g. no subtraction of followers on account deletion while all mod_follows relations of the account get deleted) this might be intended behavior to not influence follower counts when a user deletes their account but on first sight this looks like a bad practice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Relates to Modrinth Backend or API bug Something isn't working
Development

No branches or pull requests

2 participants