I'm using Thumbs up/down widget to display results on each node and I have caching enabled for anon users.
I see 50% / 50% for every node until I click on thumb up or down to get the correct result returned with Ajax.
When I click refresh on this page, I get 50% / 50% again. Any help how to set up this widget not to get cached?

CommentFileSizeAuthor
#7 1757554.patch594 bytespianomansam
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mauritsl’s picture

Status: Active » Postponed (maintainer needs more info)

Did you check the settings under "Interaction" when editing the widget?

alesr’s picture

I don't use Rate on this project any more but as I remember Interaction was set to get the results immediately.
I think the problem lies in Varnish cache.

ewheel’s picture

Same problem with 1.6.

gregoirevincke’s picture

Same problem with 1.6. BUT : do not occurs in a fresh drupal7.19 install, but in a production version, with lots of others modules installed. In the FF debug console, I have two messages concerning use of deprecated getAttributeNode(), and use of deprecated "NodeValue" attribute in jquery. Theses messages do not occurs in the fersh installation. Do not know if there is a link between theses messages and the problem.

gregoirevincke’s picture

Version: 7.x-1.3 » 7.x-1.6
Assigned: Unassigned » gregoirevincke
Category: support » bug
Status: Postponed (maintainer needs more info) » Patch (to be ported)

Forget my past message.
After some debug, i've founded the source of the problem.
The bug is due to the "Use source translation" option, wich "delete" the id of the content rated due to a lack of validity testing of the result of a node_load().

In the file rate.module, in the function rate_get_results(), at line 477 you will find :

// Check if we should use the source translation.
  if ($widget->use_source_translation) {
    $criteria['entity_id'] = _rate_get_source_translation($criteria['entity_type'], $criteria['entity_id']);
  }

Before that line $criteria['entity_id'] is equal to node id, and after that _rate_get_source_translation() function call it is = 0, so the datas extracted from the database are null.
This _rate_get_source_translation() function is defined at line 440 in rate.module :

function _rate_get_source_translation($entity_type, $entity_id) {
  if ($entity_type == 'node' && module_exists('translation')) {
    if (arg(0) == 'node' && arg(1) == $entity_id) {
      // We are on the node page. Use node_load since the node is in static cache.
      $entity_id = node_load($entity_id)->tnid;
    }
    else {
      // We are not on the node page. Do not use node_load to prevent executing many useless queries.
      $tnid = db_select('node', 'n')->fields('n', array('tnid'))->condition('n.nid', $entity_id)->execute()->fetchField();
      if ($tnid) {
        $entity_id = $tnid;
      }
    }
  }
  return $entity_id;
}

Note that there is a validity test of $tnid if we are NOT on the node page, but not if we ARE on the node page. So if node_load() return a zero value for tnid, the value of $entity_id is set to 0.
The bug is so in line 444, as there is no validity test on the result of node_load($entity_id)->tnid;.
To repair, replace :

$entity_id = node_load($entity_id)->tnid;

at line 444 by

$tnid = node_load($entity_id)->tnid;
if ($tnid) {
   $entity_id = $tnid;
}

It's the first time i report a bug correction, so i hope that i set the tags correctly.
Cheers.
Grégoire

gregoirevincke’s picture

Status: Patch (to be ported) » Needs review

I think that my tags are incorrect ("patch (to be ported)" instead of "needs review"). As they cannot be edited, here is a new post to more correctly describe the solution proposed.

pianomansam’s picture

FileSize
594 bytes

@gvincke Thank you for the fine research. Your proposed bug fix seems to be working for me. I've created a patch file for it. Can we get some more people to test this?

Yuri’s picture

Issue summary: View changes

Patching #7 does not work. Manually applied, worked.