Closed (fixed)
Project:
Advanced Poll
Version:
4.7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
6 Dec 2006 at 08:35 UTC
Updated:
25 Feb 2007 at 15:26 UTC
I created a binary poll with one possible answer. After the second guest (anonymous user) voted the total voters count started to 'look strange'. Everything else is OK, except all anonymous voters are counted for one voter (Total votes: XX). The SQL responsible for this can be found on line 949:
$result = db_query("SELECT COUNT(DISTINCT uid) AS voters FROM {votingapi_vote} WHERE content_id=%d GROUP BY uid", $node->nid);
$votes = db_num_rows($result);
I don't quite get the idea of why db_num_rows or COUNT(DISTINCT uid) (can this ever give a number other than 1?). I had to fix it quickly for the vote so I used:
SELECT COUNT(CONCAT(uid, hostname)) AS voters FROM {votingapi_vote} WHERE content_id=%d GROUP BY CONCAT(uid, hostname);
but maybe
SELECT COUNT(DISTINCT CONCAT(uid, hostname)) AS voters FROM {votingapi_vote} WHERE content_id=%d;
is enough (get the result, not number of rows. this should eat much less memory)?
Comments
Comment #1
ChrisKennedy commentedYeah, this is a known bug in 4.7 and has been fixed in the 5.0 version for a long time. I would include a ", '-', " in the CONCAT to ensure no string collisions.
Comment #2
mr700 commentedA '-' in the string concatination will do no good for string collisions - user(usera) + host(host-a.com.tw) = usera-host-a.com.tw; user(usera-host) + host(a.com.tw) = usera-host-a.com.tw. I'll take a loog at the 5.0 version...
Comment #3
mr700 commentedOps... I was wrong in my last comment - a user is infact UID, which is a number so adding anything other than a number in the string concatination solves the problem...
Comment #4
ChrisKennedy commentedAlthough the column name might suggest that it is a resolved host, hostname in VotingAPI is actually _SERVER['REMOTE_ADDR'], an IP address, so a '-' does work.
Comment #5
mr700 commentedI don't think it is fixed in the 5.0 version:
... and why db_num_rows? This actually has to transfer all the resulting rows from the server to the php script. How about:
SELECT COUNT(DISTINCT CONCAT(uid, '-', hostname)) AS voters FROM {votingapi_vote} WHERE content_id=%dComment #6
ChrisKennedy commentedThat function isn't used in 5.0; look at the comment header. The number of votes is taken from the votingapi cache and is calculated within each mode after a vote.
Comment #7
ChrisKennedy commentedOkay I went ahead and fixed this for the 4.7 version.
http://drupal.org/cvs?commit=49183
Comment #8
mr700 commentedMany thanks :-)
Comment #9
freediver-1 commentedI have the 4.7 version, which I downloaded after Dec 28. I still get this error. These are the files I downloaded:
drupal-4.7.5.tar.gz
votingapi-4.7.x-1.1.tar.gz
advpoll-4.7.x-1.x-dev.tar.gz
What did I do wrong?
http://www.ozpolitic.com/poll/drupal/
Comment #10
freediver-1 commentedI also checked the advpoll.module file and I have the corrected version.
Comment #11
freediver-1 commentedWhat's going on? Is this still a bug, or have I done something wrong?
Comment #12
freediver-1 commentedbump
Comment #13
(not verified) commentedComment #14
kiev1.org commentedhttp://drupal.org/node/96893 - not fixed
Comment #15
kiev1.org commentedit is possible error in votingapi.module - I simply deleted in
function votingapi_set_vote verification of "if (!$exists) {" - and all
works correctly
Comment #16
ChrisKennedy commentedThis issue is only for correctly displaying the number of votes. Do not reopen issues that you haven't taken the time to read.