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

ChrisKennedy’s picture

Yeah, 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.

mr700’s picture

A '-' 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...

mr700’s picture

Ops... 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...

ChrisKennedy’s picture

Although 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.

mr700’s picture

I don't think it is fixed in the 5.0 version:

function advpoll_view_electoral_list($node, $teaser = FALSE) {
  $output = '';
  if ($node->uselist) {
     $result = db_query("SELECT COUNT(*) AS voters FROM {advpoll_electoral_list} WHERE nid=%d", $node->nid);
     $electoral_list = db_fetch_object($result);
  }
  $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);
...

... 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=%d

ChrisKennedy’s picture

That 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.

ChrisKennedy’s picture

Status: Active » Fixed

Okay I went ahead and fixed this for the 4.7 version.

http://drupal.org/cvs?commit=49183

mr700’s picture

Many thanks :-)

freediver-1’s picture

I 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/

freediver-1’s picture

I also checked the advpoll.module file and I have the corrected version.

freediver-1’s picture

What's going on? Is this still a bug, or have I done something wrong?

freediver-1’s picture

bump

Anonymous’s picture

Status: Fixed » Closed (fixed)
kiev1.org’s picture

Assigned: Unassigned » kiev1.org
Priority: Normal » Critical
Status: Closed (fixed) » Active
kiev1.org’s picture

it is possible error in votingapi.module - I simply deleted in
function votingapi_set_vote verification of "if (!$exists) {" - and all
works correctly

ChrisKennedy’s picture

Assigned: kiev1.org » ChrisKennedy
Priority: Critical » Normal
Status: Active » Closed (fixed)

This issue is only for correctly displaying the number of votes. Do not reopen issues that you haven't taken the time to read.