`showOpLikes` doesn't work right away, but after clicking back and forth

AI-generated summary

The showOpLikes feature in Discourse doesn’t display original post like counts immediately, but only after clicking “sort by likes” and then returning to the latest sorting. This issue is not present with showLikes. awesomerobot suggests that showOpLikes only works when sorting by OP likes, as the op_like_count data is not included by default.

awesomerobot further explains that this behavior is intentional, likely to reduce unnecessary data transfer on every page load. However, some communities, like negaduck’s math problem forum, may find original post like counts more relevant than total topic likes.

pfaffman proposes a potential solution by adding OP likes to the serializer using JavaScript. However, negaduck has reverted to using showLikes for now, but may explore this option in the future.

Hello. I’d like to have like counts of original posts on the main page. I followed instuctions from this post: Display Like Counts on Home Page Topic List - #6 by vinothkannans

I added the following code with showOpLikes, but I have issues with it. Somehow it doesn’t show original post like counts right away. I only does this after click sort by likes and back to latest without sorting.

Interestingly, showLikes doesn’t have this issue.

<script>
var TopicListComponent = require('discourse/components/topic-list').default;
TopicListComponent.reopen({
    showOpLikes: true
});
</script>

Here is a screenshot before clicking on sort by likes and going to latest:


And this is after:

I believe showOpLikes should only work when sorting by OP likes by visiting a URL like https://meta.discourse.org/latest?order=op_likes, otherwise the op_like_count isn’t included (showLikes, should work… but that’s the total for the entire topic).

You can see this in action by viewing https://meta.discourse.org/latest.json and https://meta.discourse.org/latest.json?order=op_likes… op_like_count is only available in that second link.

Yeah, but is there any logic behind this, or is it a bug?

It’s intentionally built that way, but I’m not sure the exact reason. I suspect it’s data we don’t want to carry around on every page load.

We’ve also generally considered the total likes within a topic to be a better measurement of discussion quality than OP alone.

Well, it depends on the goals of the community I guess. Our posts represent math questions and problems, so we’d like to see the most liked ones, and I’m not sure including likes given to answers should be considered. Hm. I don’t know.

I believe that you need to add some javascript to add OP likes to the serializer. If you search “add to serializer” (perhaps without spaces) you should find some examples.

Well, I’ve changed it back to just showLikes, but thanks for the suggestion, I’ll maybe try this later.