XF 1.2 How does XF calculate a user's total number of likes received?

Gene

Member
What exactly is being counted when XF generates the "likes received" figure for a user's profile or for the notable members list? As many ways as I try and pull this figure out of the DB, it seems I come up with numbers that are a few dozen likes higher for many users than XF is reporting. Note that this isn't true for all users - my own account, for example, has not received any of these "mystery" likes, while my most prolific users (~1500 total likes) have received up to 50 or so likes that XF is ignoring when it spits out its figures.

So, ultimately, I'm wondering how XF calculates the 'total likes' figure, and where I can find this routine in the code, so that I might do the same using SQL queries.

For reference: The thread that spawned this question.
 
Last edited:
I'm not sure I understand what @Jeremy is saying there. The data is in xf_liked_content, but not every like in there may count towards the total likes received (eg, deleted threads or posts).
 
I'm not sure I understand what @Jeremy is saying there. The data is in xf_liked_content, but not every like in there may count towards the total likes received (eg, deleted threads or posts).
Correct. So in the queries I've tried, I specify that the liked content must be visible to be included in the count. The mystery likes are from something else.
 
What @Mike said. I wasn't in front of my computer to check code but knew that the total number of likes were stored in xf_user table. Sorry for the confusion! If you have mystery likes, I would start looking into what add-ons add the ability to like that you have.
 
What @Mike said. I wasn't in front of my computer to check code but knew that the total number of likes were stored in xf_user table. Sorry for the confusion! If you have mystery likes, I would start looking into what add-ons add the ability to like that you have.
ConvEss is the only addon I've got with any like-related feature.
 
It's a count that gets adjusted all over the place when various events happen... As mentioned, it's designed primarily as a cache value. The canonical data should be in xf_liked_content.
 
It's a count that gets adjusted all over the place when various events happen... As mentioned, it's designed primarily as a cache value. The canonical data should be in xf_liked_content.
Unfortunately, my XF installation is relying on like_count as the official number displayed on all profiles and the notable members list, so if that's the case, this whole "most likes in a month' contest being run by a user is based on farcical data and I have no way of verifying it in the DB. :mad:

Edit: So is this technically a bug? If XF is incorrectly calculating and displaying total likes received, I'd call that a bug.
 
Unfortunately, my XF installation is relying on like_count as the official number displayed on all profiles and the notable members list, so if that's the case, this whole "most likes in a month' contest being run by a user is based on farcical data and I have no way of verifying it in the DB. :mad:
How so? The likes counter is incremented every time someone hits the Like button, and decremented when they hit the Unlike button, and the information is stored in xf_liked_content if you need to verify it to be accurate. As far as I am aware, the current behaviour is as designed. If I were really adamant that the Likes be calculated based on content that still exists, I'd run the calculation on xf_liked_content.
 
The most simple query is:

Code:
SELECT COUNT(*) FROM `xf_liked_content`
WHERE `content_user_id` = 1

Replacing 1 with the user whose Likes you want to count, obviously. What exactly are you aiming to do beyond that?
 
Getting that data isn't the issue. The issue is that like_count (in xf_user) is what XF is using as the "official" number displayed publicly on the forum (in a user's profile, on the notable members page, etc.), but the data in like_count is incorrect - it does not match up with the number returned by variations on that query. See above for a link to the queries I've tried.
 
To clarify:

When I query xf_liked_content, I get one number of total likes.
When I query xf_post and xf_profile_post, and sum those likes, I get the same number, so it checks out.

In theory, that number should be the same as what's stored as like_count in xf_user, but it's not, leading me to believe that like_count is not up-to-date or not being calculated correctly.

XF relies on the like_count column to display total likes all throughout the forum, so this is a serious issue when users are competing for the most likes in a period of time and the forum can't even report that number correctly.

There is only one question to answer, I'm not sure why this is so difficult:
Does anyone on the team here have any idea how, when, and where XF generates the like_count column in xf_user?
 
Back
Top Bottom