mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 02:05:37 +08:00
Replace individual per-locale queries with a single query that calculates completion progress for all locales at once. This commit also removes methods off the `base_candidate` (used for Categories and Topics as well) which are not used any more, as the progress dashboard only shows progress for posts. t/162846/4 --------- Co-authored-by: Nat <natalie.tay@discourse.org>
35 lines
874 B
Ruby
Vendored
35 lines
874 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Translation
|
|
class BaseCandidates
|
|
CACHE_TTL = 1.hour
|
|
|
|
private
|
|
|
|
# ModelType that are eligible for translation based on site settings
|
|
# @return [ActiveRecord::Relation] the ActiveRecord relation of the candidates
|
|
def self.get
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def self.total_and_with_locale_count
|
|
DB.query_single(<<~SQL)
|
|
WITH eligible AS (
|
|
#{get.to_sql}
|
|
),
|
|
total_count AS (
|
|
SELECT COUNT(*) AS count FROM eligible
|
|
),
|
|
done_count AS (
|
|
SELECT COUNT(DISTINCT e.id)
|
|
FROM eligible e
|
|
WHERE e.locale IS NOT NULL
|
|
)
|
|
SELECT t.count AS total, d.count AS done
|
|
FROM total_count t, done_count d
|
|
SQL
|
|
end
|
|
end
|
|
end
|
|
end
|