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

Member count inaccurate in Guilds and Parties #12286

Open
SabreCat opened this issue Jun 9, 2020 · 13 comments · May be fixed by #15314
Open

Member count inaccurate in Guilds and Parties #12286

SabreCat opened this issue Jun 9, 2020 · 13 comments · May be fixed by #15314

Comments

@SabreCat
Copy link
Member

SabreCat commented Jun 9, 2020

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
Copy link
Contributor

paglias commented Jul 14, 2020

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
Copy link
Contributor

paglias commented Jul 14, 2020

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

@Alys Alys changed the title Member count inaccurate in Guilds Member count inaccurate in Guilds and Parties Aug 9, 2020
@lsophie
Copy link
Contributor

lsophie commented Nov 12, 2020

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

@paglias
Copy link
Contributor

paglias commented Nov 12, 2020

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

@lsophie
Copy link
Contributor

lsophie commented Dec 15, 2020

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

@Cred1Tor
Copy link
Contributor

Cred1Tor commented Jan 4, 2022

i'd like to work on this

@CuriousMagpie
Copy link
Member

Sure thing, @Cred1Tor!

@Cred1Tor
Copy link
Contributor

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
Copy link
Member Author

SabreCat commented Feb 4, 2022

@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.

@Cred1Tor Cred1Tor removed their assignment May 1, 2022
@antonderegt
Copy link
Contributor

Can I work on this one? 😃

@CuriousMagpie
Copy link
Member

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

@antonderegt
Copy link
Contributor

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!

@antonderegt antonderegt removed their assignment Nov 12, 2022
@anishlukk123
Copy link

anishlukk123 commented Jul 2, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment