-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Challenge member count can be wrong #8337
Comments
There's two separate database update commands when a user joins a Challenge and if one fails the count will be different than the actual number of participants.
|
|
|
|
|
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! |
Hello 👋 - I'd love to help out with this issue if it's still needed. Am I correct in surmising that this line has the two database update commands that should be included in the same transaction? Line const results = await Promise.all([challenge.syncTasksToUser(user), challenge.save()]); |
@SYN-tactic If you're willing to tackle this, you have our full permission to do so! Thank you! |
Awesome, thanks @CuriousMagpie - I'm on it! |
The member count listed on a challenge's page (which is taken from the challenge's document in the database) can be incorrect.
For example, for challenge 4d596684-ad74-416e-9abb-8195638247ea created on 2016-11-01, the
memberCount
in the document is 58, but a search for all players participating in the challenge shows only 53This has also been noticed in other challenges (e.g., ccba7258-bac9-41e2-b9b5-e23ff0a50bf9, b2f1dff2-d5e0-4589-8100-5fcd0049d035, 4eb1f160-29bf-4036-bc0f-9d77bcb791e3).
I'm marking this as for suggestion-discussion so that we can discuss whether we should change the code to make updating the memberCount more reliable or do away with the memberCount attribute and take the count from the members retrieved.
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!
EDIT 2020-11-20: I've removed some old comments that are no longer relevant, and added strike-through to some others that are also not as relevant for the new desired fix.
The desired fix is described in this comment: #8337 (comment)
The text was updated successfully, but these errors were encountered: