Fixed XF:ReactionScore triggered for any Reaction entity change

Affected version
2.1.7

Xon

Well-known member
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 |
+------+-------------+---------------------+-------+-------------------------------+-------------------------------+---------+------+----------+------------------------------------+
This query takes about 2 seconds or so per run, and degenerates massively as the batch size increases and the rebuild performance rapidly throttles the batch size down massively.

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.
 

XF Bug Bot

XenForo bug fixer bot
Staff member
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.1.8).

Change log:
Only enqueue a reaction score rebuild when a reaction's score has changed, and simply rebuild scores for all reactions
There may be a delay before changes are rolled out to the XenForo Community.
 
Top