Problem/Motivation

In votingapi_tokens_tokens() the second line calls _votingapi_tokens_get_entity_types() for every single token type that exists. This causes a query to the database `SELECT DISTINCT entity_type FROM {votingapi_vote}` each time. If you have a large database and receive lots of new ratings which clears mysql cache this can be very inefficient. Also in certain versions of mysql, without declaring an index on this field it can be relatively slow.

Steps to reproduce

Clear cache, watch how many times this query is run.

Proposed resolution

Simply change the logic slightly...

Change:

$entity_types = _votingapi_tokens_get_entity_types();
  foreach ($entity_types as $entity_type) {

For:

  if (strpos($type, 'votingapi_') !== 0) {
    return $replacements;
  }
  $entity_types = _votingapi_tokens_get_entity_types();
  foreach ($entity_types as $entity_type) {

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork votingapi-3417843

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

willeaton created an issue. See original summary.

viren18febs’s picture

Status: Active » Needs review
StatusFileSize
new824 bytes

I have added a mentioned changes and added a patch for this, please review

willeaton’s picture

Hi, I have an issue fork in working progress. I'll push it this morning. Didn't get chance yesterday

willeaton’s picture

Merge request uploaded

tr’s picture

Version: 8.x-3.x-dev » 4.0.x-dev
tr’s picture