If the votingapi_vote table is big (millions of record), the voting became extremely slow. This is because this query:

$sql = 'SELECT COUNT(*) FROM {votingapi_vote} WHERE vote_source = :ip AND timestamp > :time';

Needs an index of timestamp. The question is, this is a task of rate module, or should force in votingapi? I'm not sure, the votingapi have to create the index, because this module use it.

Comments

ezra-g’s picture

Project: Rate » Voting API
Version: 7.x-1.x-dev » 7.x-2.x-dev

Moving to the VotingAPI queue.

bbdata’s picture

Issue summary: View changes

Would adding an index for just the timestamp column be sufficient? Or should it be used in combination with another column?

bbdata’s picture

Issue summary: View changes

I am very sorry... fixing the issue summary.

istryker’s picture

So in the example in the summary I think an index on just the timestamp would do. Something tells me it should be vid and timestamp would be more practical. In no way am I a database expert. If you want an answer to this question, the issue queue is not the best place to ask. Try irc or find on of the contributors to the database layer in drupal core an email them.

bibo’s picture

Project: Voting API » Rate
Version: 7.x-2.x-dev » 7.x-1.7
Status: Active » Needs review
StatusFileSize
new613 bytes

This belongs to the rate-modules issue queue, as it is the (only known) module actually doing this increasingly slow query. It is an easy fix, adding one multi-column index.

So in the example in the summary I think an index on just the timestamp would do. Something tells me it should be vid and timestamp would be more practical. In no way am I a database expert.

Index on timestamp is not enough, the single index needs to cover both vote_source and timestamp. "vid" is not an option for this use case.

If you want an answer to this question, the issue queue is not the best place to ask. Try irc or find on of the contributors to the database layer in drupal core an email them.

IMO the issue queue is just the right place to ask this, if it's in the correct module (rate). Except in the case that the module creator(s) happen to be more active on IRC and not so keen on checking issue queues.

To get the index, apply the attached patch or simply run this with drush:
drush php-eval "db_add_index('votingapi_vote', 'rate_bot', array('vote_source', 'timestamp'));"

bibo’s picture

Here is a better patch that works againt latest HEAD (not master branch). The index is also checked/added during module install now.

System Lord’s picture

Has anyone been using this patch over the past 3 years that can report any issues?

quotesbro’s picture

#6 LGTM except for the codestyle (missed spaces)

ivnish’s picture

Status: Needs review » Closed (outdated)

Drupal 7 is EOL. Issue will be closed, but patches are still here

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.