-
Notifications
You must be signed in to change notification settings - Fork 3
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
Use voting_method for voting, delegations & results #227
Conversation
Add to liquid_voting_web/schema. Now can be passed in via GraphQl.
Previous unique index would have prevented participant having two or more votes with different voting methods for same proposal.
Also fix typo in voting_methods test module name. 1 test failing - expected - as not yet including voting_method upsert in vote creation. Expect more to fail as dev continues, before finally fixing to reflect new methodology.
1 test failing - expected - as not yet including |
Creates voting_method record and association with vote. All kinds of voting related tests now breaking, as expected.
This disambiguates the field from the model/struct, and results in a selector: `voting_method.name`, rather than the confusing `voting_method.voting_method`.
This makes core voting tests pass, but core voting functions mostly do not yet make appropriet use of voting_method. Also rename absinthe schema field to match model field name. Also edit vote and voting_method factories to use new model field name.
Also edit get_vote!/2 to include |> Repo.preload([:voting_method]). Also edit test of get_vote!/2 to take advantage of preload.
Also add VotingMethods as Dataloader source in absinthe schema. Also add voting_method field to vote object in absinthe schema. These changes mean we can now return the values of associated voting_method fields in a votingMethod subgroup, when returning a query of a / some Vote(s).
Use Mutli.run in lib/liquid_voting_web/resolvers/voting.ex create_vote/3 funtion. Error handling may not yet cover all possible error matching.
Also remove all_fields var where is equivalent to required_fields.
Also add error field :action to help user understand which, of 3, actions involved in create_vote (upsert voting_method, upsert_participant, create_vote) gave rise to the error.
Merges in removal of unused vars in delegations test.
Also add :voting_method to telemetry :params in create_vote/1
All tests should be green at this point.
Summary of progress:
@oliverbarnes @davefrey This feels like a good point to get some feedback / ask & answer questions. I could participate in a meeting about this, if preferred. Unfortunately, I cannot submit for review as merging this will break our Decidim demo, and I can't really fix that until the api is ready to work fully in |
Hi Simon, congrats! I can definitely review in the morning...I won't have the time to look carefully today. You might describe more your approach and decisions in the PR description, that way I can understand your intent rather than inferring from the code: it will help me separate what you wanted to do from whether the code matches. For example my first questions...again I can infer from the code, but tell us the story :-)
Apologies if this is all laid out in previous slack or git issue conversations, ideally I'd be current on all that. And if your implementation intention is set out in the issue that's 👍 for me...closely reading the issue is part of PR review, and I'll get there. |
@davefrey Thanks for the feedback! Here's some answers to your questions + some additional info:
Additional information: The fundamental change is the creation of a
|
This is looking good 🚀 I'll review again once the voting result part is done. Good point about this only being mergeable when another PR on the module side consuming the new field is ready as well, we'll need to merge them both in tandem. The only thing here that got me scratching my head so far is the updated index - I'm wondering if it's too granular. They have a cost in write time the bigger they get, and sometimes that outweighs the benefit. But I honestly need to refresh up on this topic, so I can't say for sure. This is good homework for you, @jinjagit: reading up on composite index best practices and give us a tldr on current state of our indexing, and then revisit the indexing change in this PR in light of what you find |
Thanks for the input. I'll look into it now. |
Add voting_method(name) field to asbinthe deleteDelegation mutation, in schema and delete_delegation resolver function. Update doc comments for delete/delegation/5 core function.
Also remove debug output from existing_delegations_test.exs
proposalUrl and votingMethods fields are optional, but providing only a voting method, without a proposal url, will result in an error explaining that a proposal url is required IF a voting method is specified. If a proposal url is specified, with no voting method, then votes for the proposal url and voting method with name "default" will be returned. Providing neither will return all votes for an organization. An empty list is returned if no matching result(s) found.
New file: test/liquid_voting_web/absinthe/queries/votes_test.exs.
Also remove unused vars and comments.
Note: Because we decided to use a default value for |
Video summary on YouTube @oliverbarnes @davefrey Hopefully, the video will help give an overview. |
This should not break the demo if merged, since it will |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all the work put into this, @jinjagit!
This is a big PR, but unavoidable due to the new voting_method being an almost global constraint, and much of the changes would break everything else if submitted separately.
Some of the api codebase was already due some refactoring and optimization, and some of the changes here increase that need a bit, but that tech debt is better tackled separately, in discrete and small PRs. They also take lower priority to moving ahead with integrating Decidim proposal endorsements, which depends on this PR.
I'm just going to note these small things here, for reference when tackling that:
- Repo preloads can take collections of associations, so multiple calls to it can be merged into one
- Some separate db queries might be more efficient if merged into a single one using joins
- Some function signatures are getting pretty big
- Some function are getting pretty complex, and this is already captured in some discussions here in the repo
And a subtle point: voting method sometimes comes as an argument in function signatures before proposal_url, when it's a constraint that most of the time will just use the default, and our domain it has a lower place - proposal, vote and delegation info pertain to the user actions (the user story), whereas voting method and organization id are more platform constraints - the user isn't choosing either in their voting and delegations, they're just given.
It's subtle but helps navigate the code if this hierarchy is clear and consistent :)
Going ahead and merging. Great work 👏
@oliverbarnes Great feedback. Thanks! I'll create a/some issue(s) to cover the points you make. |
Aim: To pass
voting_method
via absinthe/GraphQl, and when it is included, record and use its value appropriately.Addresses #225