diff options
author | 2025-02-20 10:13:07 +0000 | |
---|---|---|
committer | 2025-02-20 11:13:07 +0100 | |
commit | a03a35a5d6c86ef85d66bae501daaa1cd8c47c2e (patch) | |
tree | 78d745437a15d4db3ea37965fa6a40f5156eb482 /internal/db | |
parent | [chore] Step minio down to 7.0.85 (#3808) (diff) | |
download | gotosocial-a03a35a5d6c86ef85d66bae501daaa1cd8c47c2e.tar.xz |
[bugfix] update fedi api to support multiple separate votes in same multiple choice poll (#3809)
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/bundb/poll.go | 19 | ||||
-rw-r--r-- | internal/db/poll.go | 3 |
2 files changed, 18 insertions, 4 deletions
diff --git a/internal/db/bundb/poll.go b/internal/db/bundb/poll.go index 5da9832f0..d21945377 100644 --- a/internal/db/bundb/poll.go +++ b/internal/db/bundb/poll.go @@ -380,8 +380,8 @@ func (p *pollDB) PutPollVote(ctx context.Context, vote *gtsmodel.PollVote) error return err } - // Increment poll votes for choices. - poll.IncrementVotes(vote.Choices) + // Increment vote choices and voters count. + poll.IncrementVotes(vote.Choices, true) // Finally, update the poll entry. _, err := tx.NewUpdate(). @@ -394,6 +394,17 @@ func (p *pollDB) PutPollVote(ctx context.Context, vote *gtsmodel.PollVote) error }) } +func (p *pollDB) UpdatePollVote(ctx context.Context, vote *gtsmodel.PollVote, cols ...string) error { + return p.state.Caches.DB.PollVote.Store(vote, func() error { + _, err := p.db.NewUpdate(). + Model(vote). + Column(cols...). + Where("? = ?", bun.Ident("id"), vote.ID). + Exec(ctx) + return err + }) +} + func (p *pollDB) DeletePollVoteBy(ctx context.Context, pollID string, accountID string) error { // Gather necessary fields from // deleted for cache invaliation. @@ -487,8 +498,8 @@ func updatePollCounts(ctx context.Context, tx bun.Tx, deleted *gtsmodel.PollVote return err } - // Decrement votes for these choices. - poll.DecrementVotes(deleted.Choices) + // Decrement vote choices and voters count. + poll.DecrementVotes(deleted.Choices, true) // Finally, update the poll entry. if _, err := tx.NewUpdate(). diff --git a/internal/db/poll.go b/internal/db/poll.go index 88de6bfcd..2b92bd4d7 100644 --- a/internal/db/poll.go +++ b/internal/db/poll.go @@ -58,6 +58,9 @@ type Poll interface { // PutPollVote puts the given PollVote in the database. PutPollVote(ctx context.Context, vote *gtsmodel.PollVote) error + // UpdatePollVote updates the given poll vote in the database, using only given columns (else, all). + UpdatePollVote(ctx context.Context, vote *gtsmodel.PollVote, cols ...string) error + // DeletePollVoteBy deletes the PollVote in Poll with ID, by account ID, from the database. DeletePollVoteBy(ctx context.Context, pollID string, accountID string) error |