Repository navigation
Reference the voter's latest CastVote instead of copying the vote - #556
Draft
devin-ai-integration[bot] wants to merge 3 commits into
Draft
devin-ai-integration[bot] wants to merge 3 commits into
devin-ai-integration[bot] wants to merge 3 commits into
Conversation
….vote copy Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
…a vote copy Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
Author
There was a problem hiding this comment.
Devin Review found 1 finding. Devin automatically fixed it.
Fixed by Devin (1)
- Hash-only voters break or change tallies — Tally/num_cast_votes now select voters with cast_vote or vote set (old semantics for unlinked voters), and the backfill only links voters whose vote copy equals the cast vote, so hash-only voters are reported instead of linked. Test added.
This was referenced Nov 11, 2026
…fill Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Voter.voteholds a full copy of the latestCastVote.vote, which doubles the vote storage. This is step 1 of removing that copy: it addsVoter.cast_vote(FK to the latestCastVote,SET_NULL,related_name='+'), and reads go through it.Voter.voteis still written, so rolling back is safe.store_votesetscast_votein addition to the copy.last_cast_vote()returns the referenced row, or, for voters not backfilled yet, falls back to building one fromVoter.vote.compute_tallyandnum_cast_votesselect voters withcast_voteorvoteset, which is the same set as before for unlinked voters.compute_tallyiteratesselect_related('cast_vote')in chunks of 500 instead of loading every voter's vote into memory at once.ballot_listno longer loads any vote JSON (.defer('vote'), short cast votes only needvote_hashandcast_at).Migration
0013_voter_cast_vote(non-atomic, so it doesn't block cast votes on the large voter table):Backfill (
manage.py backfill_voter_cast_votes [--batch-size 1000] [-v 2]), run after deploy. It goes through unlinked voters that have avote_hashor aVoter.votecopy, in id-ordered batches, and links each one to its latestCastVotewith the samevote_hash, but only if that row's vote equals the voter's copy (as text, falling back to parsed JSON). That way the linked ballot is always the one that was being tallied. Everyone else is counted, not linked, and listed with-v 2:vote_hashbut no copyvote_hash(still tallied today, so these must be handled before the copy is dropped)The update re-checks
cast_vote_id IS NULL AND vote_hash = ..., so a voter who recasts during the backfill isn't overwritten. It can be re-run and ends with astill unlinkedcount.Later (not in this PR): once
still unlinkedis 0 (or the leftover legacy voters are handled), stop writingVoter.vote, drop the fallback,RemoveField('voter', 'vote'), thenpg_repack/VACUUM FULL helios_voterto get the space back.#554 and #555 are stacked on this PR.
Link to Devin session: https://app.devin.ai/sessions/83534237e8474452b51f8e49103c543c
Open in Devin Desktop: https://app.devin.ai/desktop/session/83534237e8474452b51f8e49103c543c?variant=devin
Requested by: @benadida
🟢 Devin fixed the finding · Follow Devin's work