mirror of
https://github.com/discourse/discourse.git
synced 2026-08-07 13:19:19 +08:00
Previously, every SQL query finding translation candidates (admin progress report and backfill jobs) filtered on `LENGTH(posts.raw)`, which forced detoasting `raw` for every scanned row and made those queries slow, while the limit itself no longer guarded anything — long posts are already split into chunks sized to the model's `max_output_tokens`, and core's `max_post_length` bounds raw size. This change removes the setting and its query filters, deletes any stored override via a post-deploy migration, and bumps the translation progress cache versions since eligibility counts change. Note for review: on existing sites, posts previously excluded by the limit become eligible for backfill, so pending counts (and translation spend on long-form content) will increase accordingly.
85 lines
2.5 KiB
Ruby
Vendored
85 lines
2.5 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Translation
|
|
class Progress
|
|
CACHE_VERSION = 2
|
|
CACHE_TTL = 2.hours
|
|
DETAIL_CACHE_VERSION = 2
|
|
DETAIL_CACHE_TTL = 2.hours
|
|
TARGET_CLASSES = {
|
|
"post" => PostCandidates,
|
|
"topic" => TopicCandidates,
|
|
"category" => CategoryCandidates,
|
|
"tag" => TagCandidates,
|
|
}.freeze
|
|
TARGETS = TARGET_CLASSES.values.freeze
|
|
|
|
def self.fetch
|
|
Discourse
|
|
.cache
|
|
.fetch(cache_key, expires_in: CACHE_TTL) do
|
|
{ cached_at: Time.now.utc.iso8601, targets: TARGETS.map(&:progress_summary) }
|
|
end
|
|
end
|
|
|
|
def self.fetch_detail(target_type)
|
|
candidate_class = TARGET_CLASSES.fetch(target_type) { raise ArgumentError, target_type }
|
|
cache_key = detail_cache_key(target_type)
|
|
|
|
cached = Discourse.cache.read(cache_key)
|
|
return cached if cached
|
|
|
|
DistributedMutex.synchronize(detail_mutex_key(cache_key), validity: 5.minutes) do
|
|
Discourse
|
|
.cache
|
|
.fetch(cache_key, expires_in: DETAIL_CACHE_TTL) do
|
|
candidate_class.progress_details.merge(cached_at: Time.now.utc.iso8601)
|
|
end
|
|
end
|
|
end
|
|
|
|
def self.supported_target?(target_type)
|
|
TARGET_CLASSES.key?(target_type)
|
|
end
|
|
|
|
def self.cache_key
|
|
[
|
|
"discourse-ai",
|
|
"translation-progress-overview",
|
|
"v#{CACHE_VERSION}",
|
|
*settings_cache_key_parts,
|
|
].join(":")
|
|
end
|
|
|
|
def self.detail_cache_key(target_type)
|
|
[
|
|
"discourse-ai",
|
|
"translation-progress-detail",
|
|
"v#{DETAIL_CACHE_VERSION}",
|
|
target_type,
|
|
*settings_cache_key_parts,
|
|
].join(":")
|
|
end
|
|
|
|
def self.settings_cache_key_parts
|
|
[
|
|
SiteSetting.content_localization_supported_locales,
|
|
SiteSetting.ai_translation_backfill_start_date,
|
|
SiteSetting.ai_translation_include_bot_content,
|
|
SiteSetting.ai_translation_personal_messages,
|
|
DiscourseAi::Translation.category_scope_cache_key,
|
|
]
|
|
end
|
|
|
|
def self.detail_mutex_key(cache_key)
|
|
"discourse_ai_translation_progress_detail_#{Digest::SHA1.hexdigest(cache_key)}"
|
|
end
|
|
|
|
private_class_method :cache_key,
|
|
:detail_cache_key,
|
|
:settings_cache_key_parts,
|
|
:detail_mutex_key
|
|
end
|
|
end
|
|
end
|