Views shows multiples results for the same vote when is enabled content translation

Created on 25 August 2023, 10 months ago
Updated 29 August 2023, 10 months ago

Problem/Motivation

The views related to voting API show the votes multiple times, seems like it is related to the join with the table Voting entity (node_field_data) in the case that the node has multiple translations.

Steps to reproduce

  • Use a vote on a node with multiple translations
  • Vote with different users
  • Visit an entity node/%node/votes or /admin/content/vote

This is the query related to the view, but adding also the langcode.

SELECT node_field_data_votingapi_vote.langcode, votingapi_vote.id AS id, votingapi_vote.entity_id, votingapi_vote.user_id
FROM votingapi_vote votingapi_vote
LEFT JOIN node_field_data node_field_data_votingapi_vote ON votingapi_vote.entity_id = node_field_data_votingapi_vote.nid
LEFT JOIN users_field_data users_field_data_votingapi_vote ON votingapi_vote.user_id = users_field_data_votingapi_vote.uid
WHERE (votingapi_vote.entity_id = '40')
ORDER BY votingapi_vote.timestamp DESC
LIMIT 10 OFFSET 0;

+-----------+------+-----------+---------+
| langcode  | id   | entity_id | user_id |
+-----------+------+-----------+---------+
| cs        | 5556 |        77 | 7777776 |
| da        | 5556 |        77 | 7777776 |
| de        | 5556 |        77 | 7777776 |
| en        | 5556 |        77 | 7777776 |
| en-uk     | 5556 |        77 | 7777776 |
| cs        | 2221 |        77 | 7777771 |
| da        | 2221 |        77 | 7777771 |
| de        | 2221 |        77 | 7777771 |
| en        | 2221 |        77 | 7777771 |
| en-uk     | 2221 |        77 | 7777771 |
+-----------+------+-----------+---------+
10 rows in set (0.002 sec)

Proposed resolution

Remove Voter (users_field_data) and Voting entity (node_field_data) from the view "Entity Votes" because are not necessary on this view.
On "All votes" are needed for the filters "name" and "title", in this case, group the results by the vote_id to avoid duplications.

"All votes" query after applying the group:

SELECT "votingapi_vote"."id" AS "id", "votingapi_vote"."type" AS "votingapi_vote_type", "votingapi_vote"."entity_id" AS "votingapi_vote_entity_id", "votingapi_vote"."entity_type" AS "votingapi_vote_entity_type", "votingapi_vote"."value" AS "votingapi_vote_value", "votingapi_vote"."vote_source" AS "votingapi_vote_vote_source", "votingapi_vote"."user_id" AS "votingapi_vote_user_id", "votingapi_vote"."timestamp" AS "votingapi_vote_timestamp", MIN(votingapi_vote.id) AS "id_1", MIN(node_field_data_votingapi_vote.nid) AS "node_field_data_votingapi_vote_nid", MIN(users_field_data_votingapi_vote.uid) AS "users_field_data_votingapi_vote_uid"
FROM
{votingapi_vote} "votingapi_vote"
LEFT JOIN {node_field_data} "node_field_data_votingapi_vote" ON votingapi_vote.entity_id = node_field_data_votingapi_vote.nid
LEFT JOIN {users_field_data} "users_field_data_votingapi_vote" ON votingapi_vote.user_id = users_field_data_votingapi_vote.uid
GROUP BY "votingapi_vote"."id", "votingapi_vote_type", "votingapi_vote_entity_id", "votingapi_vote_entity_type", "votingapi_vote_value", "votingapi_vote_vote_source", "votingapi_vote_user_id", "votingapi_vote_timestamp"
ORDER BY "votingapi_vote_timestamp" DESC
LIMIT 50 OFFSET 0
πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    10 pass
  • @eduardo-morales-alberti opened merge request.
  • Status changed to Needs review 10 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    10 pass
  • πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί

    Patch ready, I did not add an update, but maybe should be necessary to override the existing configuration.

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

    Hi,

    Thanks for the contribution. It's a little hard for me to review it because it seems that most of the changes are just re-arranging parts of the .yml file. For example. these hunks:

    @@ -1380,23 +1389,11 @@ display:
             - user.permissions
           tags: {  }
       node_page:
    -    display_plugin: page
         id: node_page
         display_title: 'Entity Votes'
    +    display_plugin: page
         position: 2
         display_options:
    -      display_extenders: {  }
    -      path: node/%node/votes
    -      menu:
    -        type: tab
    -        title: Votes
    -        description: ''
    -        expanded: false
    -        parent: ''
    -        weight: 0
    -        context: '0'
    -        menu_name: main
    -      display_description: ''
           arguments:
             entity_id:
               id: entity_id
    @@ -1405,6 +1402,9 @@ display:
               relationship: none
               group_type: group
               admin_label: ''
    +          entity_type: vote
    +          entity_field: entity_id
    +          plugin_id: numeric
               default_action: default
               exception:
                 value: all
    @@ -1420,8 +1420,8 @@ display:
               summary_options:
                 base_path: ''
                 count: true
    -            items_per_page: 25
                 override: false
    +            items_per_page: 25
               summary:
                 sort_order: asc
                 number_of_records: 0
    @@ -1433,18 +1433,32 @@ display:
               validate_options: {  }
               break_phrase: false
               not: false
    -          entity_type: vote
    -          entity_field: entity_id
    -          plugin_id: numeric
    -      defaults:
    -        arguments: false
    -        filters: false
    -        filter_groups: false
           filters: {  }
           filter_groups:
             operator: AND
             groups:
               1: AND
    +      defaults:
    +        relationships: false
    +        arguments: false
    +        filters: false
    +        filter_groups: false
    +      relationships: {  }
    +      display_description: ''
    +      display_extenders:
    +        metatag_display_extender:
    +          metatags: {  }
    +          tokenize: false
    +      path: node/%node/votes
    +      menu:
    +        type: tab
    +        title: Votes
    +        description: ''
    +        weight: 0
    +        expanded: false
    +        menu_name: main
    +        parent: ''
    +        context: '0'
         cache_metadata:
           max-age: -1
           contexts:

    I *think* the only real change made by these hunks are the addition of:

           defaults:
    +        relationships: false

    and
    + relationships: { }
    and

    -      display_extenders: { }
    +      display_extenders:
    +        metatag_display_extender:
    +          metatags: {  }
    +          tokenize: false

    but I am not completely sure. Everything else in there looks like things that have just been reordered.

    I suspect that most of these changes are core Views changes in the config schema and the way core Views orders the config properties, and I suspect that the actual functional changes made by this patch are very few? I think the relationships and metatag_display_extender items are new properties defined by Views in the three years since views.view.votingapi_votes.yml was created.

    If possible, can you separate these changes into two patches?
    The first patch would be just to update views.view.votingapi_votes.yml to the current views format/properties. I suspect this will be the majority of the changes. I think that can be done just by exporting the view and doing a diff between the export and the version that is distributed with Voting API. That could be committed first. Then the second patch would be just the changes needed for your bug fix, which I think are relatively few.

    Can you also look at #2638366: Votes not displayed when module "content translation" activated β†’ which also involves the content translation module and a similar error?

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

    Actually, the metatag_display_extender property looks to be something specific to your site, because you have the Metatags module enabled?

  • πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί

    Thank you @TR, you are totally right, I will try to export it in two patches removing parts not related to the voting as you said.

  • Status changed to Needs work 10 months ago
  • πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί
  • πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί

    Well, the issue #2638366: Votes not displayed when module "content translation" activated β†’ is from 2015 without any update or comment from other users and is from Drupal 7, so maybe I would close the issue.

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

    Yes, I'm not so concerned about D7 at this point, but I assume that if it was a problem in D7 it's probably also a problem in D8+, so if it's simple to test I would like to see if this problem still exists in the current version of Drupal/Voting API before I dismiss that old bug report.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    10 pass
  • Status changed to Needs review 10 months ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    10 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.3 & MySQL 5.7
    last update 10 months ago
    10 pass
  • πŸ‡ͺπŸ‡ΈSpain Eduardo Morales Alberti Spain, πŸ‡ͺπŸ‡Ί

    I upload the patch voting_api-3383319-views-drupal-clean-nochanges-11.patch β†’ after installing the votingapi on a drupal 9 clean, without other modules and exports the view, there are no deletions or additions, only changes in the ordering.

    I also update the real changes interdiff_only_views_changes.txt β†’ , I remove the relationships on the "Entity votes" because is not necessary, and add the group by to both view pages.

    I updated the current patch removing metatags.

Production build 0.69.0 2024