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
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | issues-3417843-Query-entity-types-for-each-token-hook-fixes.patch | 824 bytes | viren18febs |
Issue fork votingapi-3417843
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
Comment #2
viren18febs commentedI have added a mentioned changes and added a patch for this, please review
Comment #3
willeaton commentedHi, I have an issue fork in working progress. I'll push it this morning. Didn't get chance yesterday
Comment #4
willeaton commentedMerge request uploaded
Comment #5
tr commentedComment #6
tr commented