- Affected version
- 2.1.7
XF\Job\ReactionScore
is being triggered for any change (including insert of new records!) even if the reaction_score
has not changed;
PHP:
protected function _postSave()
{
$this->app()->jobManager()->enqueueUnique('reactionChange' . $this->reaction_id, 'XF:ReactionScore', [
'reaction_id' => $this->reaction_id
]);
$this->rebuildReactionCache();
}
This query;
SQL:
SELECT DISTINCT content_user_id
FROM xf_reaction_content
WHERE reaction_id=1 AND content_user_id > 0
ORDER BY content_user_id
limit 100;
Has a very suboptimal query plan when there are a large number of rows;
Code:
+------+-------------+---------------------+-------+-------------------------------+-------------------------------+---------+------+----------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+---------------------+-------+-------------------------------+-------------------------------+---------+------+----------+------------------------------------+
| 1 | SIMPLE | xf_reaction_content | range | content_user_id_reaction_date | content_user_id_reaction_date | 4 | NULL | 66001380 | Using index condition; Using where |
+------+-------------+---------------------+-------+-------------------------------+-------------------------------+---------+------+----------+------------------------------------+
Simply put; the entire
reaction_id
specific path probably isn't worth keeping. And this definitely should not be triggered for any change to the reaction definition.