Admins editing comment-based ratings saves a new vote

Timur5 - November 7, 2008 - 16:45
Project:Fivestar
Version:6.x-1.13
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

I'm voting on my own website as anonymous multiple times.
Each time I add a new vote, the number of votes increases by 2 instead of 1.
E.g.

Was:
Average: 2.5 (12 votes)

After voting once as anonymous became:
Average 2.6 2.5 (14 votes)

#1

quicksketch - November 10, 2008 - 01:05

This might be because of page caches. Try turning off page caching at admin/settings/performance, and see if the problem is corrected.

I don't think it's actually a bug, what might be happening is something like this:

- Page caching is turned on and set to 5 minutes
- Anonymous user A hits a page, which is then put in the page cache.
- The rating on this page is currently at 4 votes, anonymous user A casts another vote and sees the vote count increase to 5
- Anonymous user B hits the same page, but see the rating on the page at 4 votes still (despite user A increasing it to 5). User B votes, then sees the count increase from 4 to 6.

Some ways you can get around this could be reducing the page cache time (I never use higher than 5 minutes) to reduce the effect of this happening. On a normal site, you should be fine with a 1 or 2 minute cache time.

I might be completely wrong though. Please let me know if this helped with the problem.

#2

Timur5 - November 14, 2008 - 13:04

Thank you for looking at my problem. I checked, cashing is disabled.
The problem remains, and I wasn't able to figure out why.

So, I'll be reinstalling the whole Drupal over and all modules to it and then check it again. If no one has this problem, then there is something wrong on my side.
I'll report about the results when done with the re-installation.

#3

quicksketch - November 14, 2008 - 21:57

Thanks Timur5, I'll review the problem again on my side also and see if I can reproduce, I just suspected caching as it can sometimes cause odd results.

#4

Timur5 - November 15, 2008 - 10:42

Ok, I'm back with the results: new Drupal, new modules - again I have 2 votes instead of one :(
I'll try to describe it in full:

1. Drupal 6.6, Fivestar 6.x-1.13 - both newly installed.
2. Theme - garland.
3. Caching disabled.
4. Anonymous users can leave comments, but admin approval is required.
5. Making new content type called: votepage. Enabling 5 star voting.
6. Using standard 5 stars. Star display style: display average vote value. Text display style: current average in text. Allow undoing votes. Full node display: static display above node body. Fivestar comment settings: optional rating.
7. Creating content - new votepage.
8. Visiting this page from another browser as Anonymous. Clicking add comment. Comment appears in a new window. Voting and adding a comment. Comment is held for moderation. Current results seen on votepage are good: Average 5 (1 vote)
9. Now going back to admin panel and approving the vote. And here I get the double vote results upon comment approval: Average 5 (2 votes). Although only one anonymous user has voted.

Thank you.

#5

quicksketch - November 16, 2008 - 01:27
Title:Anonymous votes count as two» Admins editing comment-based ratings saves a new vote

Thanks Timur5, for this excellent summary. I was able to reproduce it right away.

Here's the situation that's occurring:
- Anonymous user leaves a moderated comment with a rating. This rating is immediately saved and the vote increment increases to 1.
- Admin comes to approve the comment. Upon approving the comment, a second vote is cast, this time as if the admin had voted according to the comment's rating that was just approved and the vote increment increases to 2 (one by the anonymous user, one by the administrator).

It looks like this problem is specific to anonymous voting through the the Fivestar Comment module, so thanks again for the walkthrough, it would've been hard to uncover otherwise.

The root of the problem came from Fivestar not retrieving anonymous votes properly. Since Fivestar defaults to returning nothing when asking for an anonymous vote, it was assuming that no vote had yet been cast and then would cast a second vote as the administrator when the administrator edited the comment.

So this patch addresses some much deeper problems in Fivestar, unfortunately it's not small and will take some work porting to Drupal 5, but I think that it will solve the problem you're having. Could you try out this patch and let me know if it has any noticeable side-effects (besides fixing the comment problem, of course :).

AttachmentSize
fivestar_comment_moderate.patch 10.77 KB

#6

quicksketch - November 16, 2008 - 01:27
Status:active» needs review

Oh, I also forgot to mention something else this patch accomplishes. When a comment is now moderated, the rating is not saved until it is approved.

#7

Timur5 - November 17, 2008 - 21:28

Thank you, quicksketch!

Today tried on my test website. The problem is solved - it calculates the number of votes correctly when admin approves the comment.
Tomorrow I'll apply the patch to my existing website and will test it further for any side-effects.
I'll write an extra report as soon as I'm done.

#8

quicksketch - November 17, 2008 - 21:57
Status:needs review» needs work

I realized some further troubles with this patch though. I don't handle when a comment is put INTO moderation. In such cases, the vote should probably be removed until the comment is published again. Thanks for trying it out though, good to know we at least found where the problem is.

#9

Timur5 - November 19, 2008 - 20:40

true, I'll be waiting for a fix.

It seem to have stopped working :)
It counts only the most recent vote (whether from registered user or anonymous).
No matter how many voters have voted, it always displays the star rating sbmitted by the last voter and it always says that only 1 voter had voted so far.

Thank you for all the great work!

#10

Timur5 - October 10, 2009 - 15:58

Ok, here is the question while the fix is pending. (I love fivestar, so my website uses it despite the bug, I hope the last one will be fixed when the time comes.)

How to manually edit MYSQL database to remove/edit incorrect rating?

Problem description: since we have a double vote caused by admin approval, when it comes to deleting a vote, only one is deleted, while the second (caused by admin) remains, thus continuing to affect overall rating calculation. I tried to locate the column responsible for vote calculation in MYSQL, but apparently there is more than just one field involved.

Can someone point which columns/table fields in MYSQL should I look to edit?
Thank you.

#11

sedmi - November 13, 2009 - 12:51

How to apply this patch to version 6.x-1.19?

 
 

Drupal is a registered trademark of Dries Buytaert.