HabitRPG / habitica

A habit tracker app which treats your goals like a Role Playing Game.
https://habitica.com
Other
11.82k stars 4.05k forks source link

Member count inaccurate in Guilds and Parties #12286

Open SabreCat opened 4 years ago

SabreCat commented 4 years ago

Description

Clean-up of #7454. You can visit that ticket to see the full history of discussion on this issue. Split off from #12275; that ticket can be addressed first.

memberCount in group records is a stored computed value that we currently attempt to keep up to date by incrementing and decrementing as members join and leave. It frequently gets out of sync, leading to people needing to visit the Report a Bug Guild to have their Guild memberships updated.

This is the desired fix:

change the group remove, leave and join routes to recompute memberCount each time it needs to be updated (i.e., count all existing members, rather than add or subtract one from the current value of memberCount)

However, this is likely to be performance-intensive under current Mongo functionality. This ticket will remain on hold until we can upgrade to a version that allows transactions, which will allow us to make a complete fix.


With PR #12335 the Habitica codebase has been updated to support MongoDB 4.2 and transactions making it possible to fix this issue.

Transactions allow operations on multiple documents to be executed ensuring that either all of them are executed correctly or none, making it possible to fix this issue.

An example on using transactions can be found at https://mongoosejs.com/docs/transactions.html while more info at https://docs.mongodb.com/manual/core/transactions/. If you want to work on this issue and have any question please leave a comment!

paglias commented 4 years ago

With PR #12335 the Habitica codebase has been updated to support MongoDB 4.2 and transactions making it possible to fix this issue.

Transactions allow operations on multiple documents to be executed ensuring that either all of them are executed correctly or none, making it possible to fix this issue.

An example on using transactions can be found at https://mongoosejs.com/docs/transactions.html while more info at https://docs.mongodb.com/manual/core/transactions/. If you want to work on this issue and have any question please leave a comment!

paglias commented 4 years ago

If you work on this the code used for guilds should also replace the existing one to make sure parties member count is accurate

lsophie commented 3 years ago

Hi, is this issue open to being worked on? If so, I'd love to pick it up!

paglias commented 3 years ago

@lsophie it's available but since you already claimed another issue let's wait until that's done

lsophie commented 3 years ago

Hello, I'd love to take on this issue if it's still available!

Cred1Tor commented 2 years ago

i'd like to work on this

CuriousMagpie commented 2 years ago

Sure thing, @Cred1Tor!

Cred1Tor commented 2 years ago

i'm wondering what operations should be a part of a transaction? only where memberCount and user's membership are involved or everything else as well, like updating group plan, challenges, tasks etc? and in that case we'll also have to change some of the group schema methods' signatures to add a session as a parameter, bc some of the db operations happen there

SabreCat commented 2 years ago

@Cred1Tor I'd suggest starting with the operations that update counts, because they've been thorns in our collective side for ages! And that's what's relevant to this specific issue ticket. There could definitely be other places where transactions would be beneficial, but let's get this piece done first.

antonderegt commented 2 years ago

Can I work on this one? 😃

CuriousMagpie commented 2 years ago

@antonderegt If you're feeling up to it, sure thing! 😁

antonderegt commented 1 year ago

Unfortunately I've not been able to fully fix the issue in a timely manner. Please see #14203 for a partial fix. The only tasks left are to create a new error message (for when the transaction is rolled back) and implementing the fix to all places where member count is changed.

Good luck!

anishlukk123 commented 2 months ago

@CuriousMagpie @SabreCat could I work on this if still a relavant issue