HermanMartinus / bearblog

Free, no-nonsense, super fast blogging.
MIT License
2.37k stars 73 forks source link

Number of toasts in analytics doesn't match number of toasts on post page #235

Closed hexpunk closed 1 year ago

hexpunk commented 1 year ago

Posts that show zero toasts on the analytics page often show one toast on the post page itself. I'm not sure how to account for this. I'm certain it's not based on the period of time being displayed in analytics because this remains true even when "All time" is chosen. I'm thinking it's actually the number on the post page itself that may be incorrect. This is because I've seen preview pages for unpublished draft posts that show one toast on them. I'm also unable to toast my own posts. I'm not sure if this is by design or if I'm somehow toasting my own posts automatically, accounting for that mysterious single toast that doesn't appear in analytics. All I know is that the posts say they have one toast even while in draft and the toast button reads "toasted" as if I clicked on it.

I tried looking around the code, but nothing obvious stands out to me as the reason for the inconsistency.

HermanMartinus commented 1 year ago

I've dug into it and can't seem to recreate this issue. Some things to take into account:

I'll dig into this a bit more today, but I think it's working okay.

HermanMartinus commented 1 year ago

Ah, I found the issue. You weren't incorrect.

In this code where it calculates the score for the discovery feed is also where it sets the post's upvote count:

    def update_score(self):
        self.upvotes = self.upvote_set.count()

        if self.upvotes > 1:
            log_of_upvotes = log(self.upvotes, 10)

            seconds = self.published_date.timestamp()
            if seconds > 0:
                score = (log_of_upvotes) + ((seconds - 1577811600) / (14 * 86400))
                self.score = score

            self.save()
        return

If the number of upvote records is less than 1, then the upvote count isn't set because the self.save() only triggers when there's more than one. It was a small issue that went unnoticed for a long time since it only affected the first upvote.

I've fixed it 👍 Thanks for pointing it out

hexpunk commented 1 year ago

Thank you for fixing this. The numbers make sense again. 🙏