# Solved count in summary displaying incorrect values

**URL:** https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134
**Category:** Bug
**Tags:** solved
**Created:** [March 27, 2025, 11:18am UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134 "2025-03-27T11:18:13Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![dr460nf1r3](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dr460nf1r3/32/484691_2.png) [@dr460nf1r3](https://meta.discourse.org/u/dr460nf1r3)
#### Post date: [March 27, 2025, 11:18am UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/1 "2025-03-27T11:18:13Z")

</div>

Hey everyone,

After updating our Discourse instance, we seemingly have incorrect solved amounts when looking at profile summaries. Example:

- Wrong: [Profile - dr460nf1r3 - Garuda Linux Forum](https://forum.garudalinux.org/u/dr460nf1r3/summary)
- Correct (from profile popup):  
 ![This image shows a screenshot displaying a user profile from a social media platform, indicating the user has recently posted, joined the platform on April 27, 2020, and read 40 posts and 485 solutions, with a prompt to view 475 more posts in the "D" section. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/6/0/c/60ccb8f8525f129f167764b19ddcb5fa71dafbf9.png)

I already noticed there were a couple of changes lately, including a breaking bug:

> [@Solved topic cannot be loaded](https://meta.discourse.org/t/solved-topic-cannot-be-loaded/358947/7):
>
> We _just_ moved discourse-solved away from using custom fields into proper tables, and there had been some assumptions made like each post should only be an answer to a topic, or a topic with an answer must point to a non-null post. All these assumptions were thrown out of the window

The correct amounts are obviously still available so there was likely something happening while migrating the data to the new tables?

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [March 27, 2025, 11:35am UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/2 "2025-03-27T11:35:04Z")

</div>

Thanks for writing in. I’ll have a look.

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [March 27, 2025, 11:55am UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/4 "2025-03-27T11:55:55Z")

</div>

There are some discrepancies in counting solutions in Discourse where we were including topics and posts that have already been deleted.

Before the migration, we were indicating:

> John has 27 solutions because people marked his post as solution 27 times.

This is stored in the UserActions table.

After the migration, we are now counting:

> John has 20 solutions because there are 20 topics where his posts are solutions

This is stored in the SolvedTopics table, and has a direct link to an existing, non-deleted topic.

There’s a subtle difference here - in the first scenario there were no validations in checking if the solution post or its topic still existed.

I’ll check in with our team which is the better number to display. Personally I am leaning counting solutions for topics that still exist.

---

<div class="post-metadata">

### Author: ![dr460nf1r3](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dr460nf1r3/32/484691_2.png) [@dr460nf1r3](https://meta.discourse.org/u/dr460nf1r3)
#### Post date: [March 27, 2025, 12:03pm UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/5 "2025-03-27T12:03:10Z")

</div>

I’m quite sure that this can’t be the issue — as it would only cause fewer numbers rather than more in some cases, correct? There is another example I have for you:  
 → Wrong: [Profile - SGS - Garuda Linux Forum](https://forum.garudalinux.org/u/sgs/summary)  
 → Right:  
 ![The image displays a user profile section showing that the user joined on April 15, 2020, has read 600 hours of content, and posted 4 hours ago, with a current streak of 5 consecutive days. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/7/9/3/7934cd896119248ae9f187fdf63610c14c05fcc7.png)

It seems impossible to me that this counting mechanism would more than double the amount of solved post counts. Besides that (of course unconfirmed) I highly doubt that the number of deleted posts was this high in my previous example.

Thanks!

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [March 27, 2025, 12:20pm UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/7 "2025-03-27T12:20:03Z")

</div>

Hmmm yes 485 and 90 are too wide apart.

I believe just found the bug (though the statement about discrepancy I mentioned above is still true) –

In the [previous implementation](https://github.com/discourse/discourse-solved/blob/e82c6ae1ca38ccebb34669148f8de93a3028906e/lib/discourse_solved/user_summary_extension.rb#L6-L8), the solution count in John’s summary is counted by _the number of times anyone marked the John’s post as solution_

```plaintext
  def solved_count
    UserAction.where(user: @user).where(action_type: UserAction::SOLVED).count
  end

```

In the [new implementation](https://github.com/discourse/discourse-solved/blob/main/lib/discourse_solved/user_summary_extension.rb#L6-L8), the solution count in John’s user summary is the number of times John marked a post as solution

```plaintext
  def solved_count
    DiscourseSolved::SolvedTopic.where(accepter: @user).count
  end

```

This explains the large difference. “solved count” changed definitions from ‘how many times you answered’ to ‘how many times you accepted’.

Will fix the bug, thanks again for the report!

I’ll also update the different counting methods used in profile popup and user summary.

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [March 27, 2025, 12:41pm UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/8 "2025-03-27T12:41:58Z")

</div>

Props to @ondrej for also mentioning [Solution badge not working?](https://meta.discourse.org/t/solution-badge-not-working/352996) to me. It looks like some discrepancies were already happening before this migration. Good thing is that we’ll be migrating to a more consistent number across Discourse and our plugins.

---

<div class="post-metadata">

### Author: ![dr460nf1r3](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dr460nf1r3/32/484691_2.png) [@dr460nf1r3](https://meta.discourse.org/u/dr460nf1r3)
#### Post date: [March 27, 2025, 2:42pm UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/10 "2025-03-27T14:42:29Z")

</div>

Wonderful, thank you very much! 🙂

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [March 28, 2025, 1:50am UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/13 "2025-03-28T01:50:17Z")

</div>

This is now fixed and standardised - [FIX: Standardise the definition of what a solution is by nattsw · Pull Request #352 · discourse/discourse-solved · GitHub](https://github.com/discourse/discourse-solved/pull/352)

---

<div class="post-metadata">

### Author: ![nat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nat/32/235063_2.png) [@nat](https://meta.discourse.org/u/nat)
#### Post date: [March 31, 2025, 12:00am UTC](https://meta.discourse.org/t/solved-count-in-summary-displaying-incorrect-values/359134/14 "2025-03-31T00:00:16Z")

</div>

This topic was automatically closed after 2 days. New replies are no longer allowed.
