XF 2.1 Reaction score showing likes only on notable members lists

Mr Lucky

Well-known member
Possibly this is an issue after Content Ratings import (have already mention on Content ratings thread) but I get the feeling this may rather be a xenforo issue, as surely in both the list and in the members eaters we should see Reaction score, not just like count.

In the list of top 5 reaction score we see only the likes count instead of the total Reaction count

198300

But then when clicking through to the member details it is showing the correct Reactions score (based on the 5 types of positive reactions, not just likes)

198299

Surely both of these fields should be linking to same count?

Can anyone please help?
 

Jake B.

Well-known member
All of the things on /members come from a cached value in the xf_member_stat table, I'm not sure what could cause a desync between the two, but do you use any add-ons that would have touched/rebuilt this data?
 

Chris D

XenForo developer
Staff member
any add-ons that would have touched/rebuilt this data?
I was just about to comment on that.

It appears as though there is an import from a Reactions/Ratings add-on involved, so I'm guessing that the import has been done, the reaction score has been rebuilt, but the member stat still has the cached value.

By default we cache for 60 minutes so I'm going to guess that the next time @Mr Lucky checks it will be fixed.
 

Mr Lucky

Well-known member
All of the things on /members come from a cached value in the xf_member_stat table, I'm not sure what could cause a desync between the two, but do you use any add-ons that would have touched/rebuilt this data?
But I'll see what happens if I disable all adding, and rebuild reaction caches
 

Chris D

XenForo developer
Staff member
Admin > Users > Member statistics > Highest reaction score

In there there is a "Cache this stat for X minutes" option.

Uncheck that and visit the Members page again - that should refresh it straight away.

We'd recommend putting the caching back on, though after. It defaults to 60 minutes, I think.
 

Mr Lucky

Well-known member
I am unable to untick that box, the tick remains. Also cannot reduce or add to the number of minutes.

Have tried with debug and still cannot change it.
 

Brad Padgett

Well-known member
I am unable to untick that box, the tick remains. Also cannot reduce or add to the number of minutes.

Have tried with debug and still cannot change it.

I just tested development mode out versus debug and that works. I'm going to attempt this upgrade to import ratings to reactions after making backups as i go. Should work without a problem.
 

Brad Padgett

Well-known member
Yes, that was my issue, I didn't know about development mode (but got informed in another thread). I imagine you must still rebuild cache but should show immediately once you untick that box.

Just a quick question before I attempt this. @Jake B. had mentioned there isn't a "content reaction" rebuild tool. What does that mean? The screenshot above you showed. Are those the default reaction cache rebuilds or is one of them from andy b's addon?
 

Brad Padgett

Well-known member
@Chris D care to chime in? I want to do this right. This is due to content ratings Xon has not be upgraded yet. I know you don't recommend these types of actions but I know what I'm doing and will have backups regardless of any issue that may occur.

But I'm curious as to whether the "rebuild reaction score" option in the above screenshot is from andy b's addon or if that's actually apart of 2.1.x
 

Jake B.

Well-known member
But I'm curious as to whether the "rebuild reaction score" option in the above screenshot is from andy b's addon or if that's actually apart of 2.1.x

That one rebuilds the reaction_score value in the user table with the value obtained from:

PHP:
/** @var \XF\Repository\Reaction $reactionRepo */
$reactionRepo = $this->app->repository('XF:Reaction');
$count = $reactionRepo->getUserReactionScore($id);

which gets the score from this query:

PHP:
return intval($this->db()->fetchOne("
   SELECT SUM(reaction.reaction_score)
   FROM xf_reaction_content AS content
   INNER JOIN xf_reaction AS reaction ON
      (content.reaction_id = reaction.reaction_id)
   WHERE content.content_user_id = ?
      AND content.is_counted = 1
", $userId));

It shouldn't be able to change how the actual reactions appear in content. We had to add in a content reaction cache rebuild job (which luckily is able to run a function that XenForo defines) to fix discrepancies in the content caches:

198488

To rebuild the actual reaction content cache all that ultimately has to happen is running the following for all content:

Code:
$this->repository('XF:Reaction')->rebuildContentReactionCache($contentType, $contentId);

The way we've accomplished this is by looping through all of the content types (or only the specific content type you've selected) and getting a unique list of content IDs within that content type with the following function:

PHP:
$this->db()->fetchAllColumn('
    SELECT DISTINCT(content_id)
    FROM xf_reaction_content
    WHERE content_type=?
      AND content_id > ?
    LIMIT ?
    ', [
    $this->contentType,
    $startAt,
    $limit
]);

then triggering the above repository function with the values we've loaded here. Honestly not sure why XenForo didn't include this as it's quite helpful if you disable a reaction and want to reenable it at a later date, but I'm sure they have their reasons. We also allow this to be run via a CLI command:

Code:
php cmd.php threactplus-content-reaction-cache
 
Top