discourse/plugins/discourse-solved/lib/discourse_solved/queries.rb
Régis Hanol aa94311d97
DEV: refactor user card/summary accepted answer's query (#35500)
In
be5798f6d8
we standardized the way we counted a user's accepted answers.

This makes it a little bit more obvious by refactoring the query into it
own files (queries.rb) and using that in both the user card and user
summary serializers.

Also improved the specs coverage.

Internal ref - t/149121
2025-10-31 08:49:36 +01:00

13 lines
355 B
Ruby

# frozen_string_literal: true
module DiscourseSolved
module Queries
def self.solved_count(user_id)
DiscourseSolved::SolvedTopic
.joins(answer_post: :user, topic: {})
.where(posts: { user_id: user_id, deleted_at: nil })
.where(topics: { archetype: Archetype.default, deleted_at: nil })
.count
end
end
end