Calculate votes on empty sets of votes

Created on 7 March 2021, about 4 years ago
Updated 20 November 2024, 5 months ago

Motivation

I am writing a VoteResultFunction plugin for the module like and dislike β†’ that calculates the total of likes substracting the number of dislikes. This module defines two vote types for liking and disliking so I access data from other votes types when calculating. The problem comes when the last vote from an entity is removed so all the calculations are deleted and since there is no more votes to calculate the result for that entity remains deleted in the votingapi_results table.

Steps to reproduce

Recalculate votes for an entity with no votes.

Proposed resolution

Tally votes even for empty sets

Remaining tasks

Code it.

API changes

VoteResultFunction plugins can receive empty arrays.

Data model changes

When deleting the last vote of an entity the results will be calculated so for example the VoteResultFunction shipped with the module will store zeroes.

✨ Feature request
Status

Needs work

Version

4.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain rodrigoaguilera Barcelona

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    MR needs to be rebased against 4.0.x. But it looks like a reasonable improvement on the code. The only thing I think needs to be added is a test to make sure the result functions work when there are no votes - your patch fixes that for the Average function, but if we add new functions in the future or if some dependent module adds some result functions, then we want to have this test to make sure those functions don't have the same problem.

Production build 0.71.5 2024