Merge commit 'c15c8c7aa8
' into kb_migration
This commit is contained in:
commit
093cfdbb7b
208 changed files with 2976 additions and 5888 deletions
|
@ -16,7 +16,9 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure
|
|||
protected
|
||||
|
||||
def perform_total_query
|
||||
Account.where(domain: params[:domain]).count
|
||||
domain = params[:domain]
|
||||
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
||||
Account.where(domain: domain).count
|
||||
end
|
||||
|
||||
def perform_previous_total_query
|
||||
|
@ -24,13 +26,21 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure
|
|||
end
|
||||
|
||||
def perform_data_query
|
||||
account_matching_sql = begin
|
||||
if params[:include_subdomains]
|
||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))"
|
||||
else
|
||||
'accounts.domain = $3::text'
|
||||
end
|
||||
end
|
||||
|
||||
sql = <<-SQL.squish
|
||||
SELECT axis.*, (
|
||||
WITH new_accounts AS (
|
||||
SELECT accounts.id
|
||||
FROM accounts
|
||||
WHERE date_trunc('day', accounts.created_at)::date = axis.period
|
||||
AND accounts.domain = $3::text
|
||||
AND #{account_matching_sql}
|
||||
)
|
||||
SELECT count(*) FROM new_accounts
|
||||
) AS value
|
||||
|
@ -53,6 +63,6 @@ class Admin::Metrics::Measure::InstanceAccountsMeasure < Admin::Metrics::Measure
|
|||
end
|
||||
|
||||
def params
|
||||
@params.permit(:domain)
|
||||
@params.permit(:domain, :include_subdomains)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,9 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
|||
protected
|
||||
|
||||
def perform_total_query
|
||||
Follow.joins(:account).merge(Account.where(domain: params[:domain])).count
|
||||
domain = params[:domain]
|
||||
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
||||
Follow.joins(:account).merge(Account.where(domain: domain)).count
|
||||
end
|
||||
|
||||
def perform_previous_total_query
|
||||
|
@ -24,6 +26,14 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
|||
end
|
||||
|
||||
def perform_data_query
|
||||
account_matching_sql = begin
|
||||
if params[:include_subdomains]
|
||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))"
|
||||
else
|
||||
'accounts.domain = $3::text'
|
||||
end
|
||||
end
|
||||
|
||||
sql = <<-SQL.squish
|
||||
SELECT axis.*, (
|
||||
WITH new_followers AS (
|
||||
|
@ -31,7 +41,7 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
|||
FROM follows
|
||||
INNER JOIN accounts ON follows.account_id = accounts.id
|
||||
WHERE date_trunc('day', follows.created_at)::date = axis.period
|
||||
AND accounts.domain = $3::text
|
||||
AND #{account_matching_sql}
|
||||
)
|
||||
SELECT count(*) FROM new_followers
|
||||
) AS value
|
||||
|
@ -54,6 +64,6 @@ class Admin::Metrics::Measure::InstanceFollowersMeasure < Admin::Metrics::Measur
|
|||
end
|
||||
|
||||
def params
|
||||
@params.permit(:domain)
|
||||
@params.permit(:domain, :include_subdomains)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,9 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
|||
protected
|
||||
|
||||
def perform_total_query
|
||||
Follow.joins(:target_account).merge(Account.where(domain: params[:domain])).count
|
||||
domain = params[:domain]
|
||||
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
||||
Follow.joins(:target_account).merge(Account.where(domain: domain)).count
|
||||
end
|
||||
|
||||
def perform_previous_total_query
|
||||
|
@ -24,6 +26,14 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
|||
end
|
||||
|
||||
def perform_data_query
|
||||
account_matching_sql = begin
|
||||
if params[:include_subdomains]
|
||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))"
|
||||
else
|
||||
'accounts.domain = $3::text'
|
||||
end
|
||||
end
|
||||
|
||||
sql = <<-SQL.squish
|
||||
SELECT axis.*, (
|
||||
WITH new_follows AS (
|
||||
|
@ -31,7 +41,7 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
|||
FROM follows
|
||||
INNER JOIN accounts ON follows.target_account_id = accounts.id
|
||||
WHERE date_trunc('day', follows.created_at)::date = axis.period
|
||||
AND accounts.domain = $3::text
|
||||
AND #{account_matching_sql}
|
||||
)
|
||||
SELECT count(*) FROM new_follows
|
||||
) AS value
|
||||
|
@ -54,6 +64,6 @@ class Admin::Metrics::Measure::InstanceFollowsMeasure < Admin::Metrics::Measure:
|
|||
end
|
||||
|
||||
def params
|
||||
@params.permit(:domain)
|
||||
@params.permit(:domain, :include_subdomains)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,7 +26,9 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
protected
|
||||
|
||||
def perform_total_query
|
||||
MediaAttachment.joins(:account).merge(Account.where(domain: params[:domain])).sum('COALESCE(file_file_size, 0) + COALESCE(thumbnail_file_size, 0)')
|
||||
domain = params[:domain]
|
||||
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
||||
MediaAttachment.joins(:account).merge(Account.where(domain: domain)).sum('COALESCE(file_file_size, 0) + COALESCE(thumbnail_file_size, 0)')
|
||||
end
|
||||
|
||||
def perform_previous_total_query
|
||||
|
@ -34,6 +36,14 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
end
|
||||
|
||||
def perform_data_query
|
||||
account_matching_sql = begin
|
||||
if params[:include_subdomains]
|
||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))"
|
||||
else
|
||||
'accounts.domain = $3::text'
|
||||
end
|
||||
end
|
||||
|
||||
sql = <<-SQL.squish
|
||||
SELECT axis.*, (
|
||||
WITH new_media_attachments AS (
|
||||
|
@ -41,7 +51,7 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
FROM media_attachments
|
||||
INNER JOIN accounts ON accounts.id = media_attachments.account_id
|
||||
WHERE date_trunc('day', media_attachments.created_at)::date = axis.period
|
||||
AND accounts.domain = $3::text
|
||||
AND #{account_matching_sql}
|
||||
)
|
||||
SELECT SUM(size) FROM new_media_attachments
|
||||
) AS value
|
||||
|
@ -64,6 +74,6 @@ class Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure < Admin::Metrics:
|
|||
end
|
||||
|
||||
def params
|
||||
@params.permit(:domain)
|
||||
@params.permit(:domain, :include_subdomains)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,9 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
|||
protected
|
||||
|
||||
def perform_total_query
|
||||
Report.where(target_account: Account.where(domain: params[:domain])).count
|
||||
domain = params[:domain]
|
||||
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
||||
Report.where(target_account: Account.where(domain: domain)).count
|
||||
end
|
||||
|
||||
def perform_previous_total_query
|
||||
|
@ -24,6 +26,14 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
|||
end
|
||||
|
||||
def perform_data_query
|
||||
account_matching_sql = begin
|
||||
if params[:include_subdomains]
|
||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $3::text))"
|
||||
else
|
||||
'accounts.domain = $3::text'
|
||||
end
|
||||
end
|
||||
|
||||
sql = <<-SQL.squish
|
||||
SELECT axis.*, (
|
||||
WITH new_reports AS (
|
||||
|
@ -31,7 +41,7 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
|||
FROM reports
|
||||
INNER JOIN accounts ON accounts.id = reports.target_account_id
|
||||
WHERE date_trunc('day', reports.created_at)::date = axis.period
|
||||
AND accounts.domain = $3::text
|
||||
AND #{account_matching_sql}
|
||||
)
|
||||
SELECT count(*) FROM new_reports
|
||||
) AS value
|
||||
|
@ -54,6 +64,6 @@ class Admin::Metrics::Measure::InstanceReportsMeasure < Admin::Metrics::Measure:
|
|||
end
|
||||
|
||||
def params
|
||||
@params.permit(:domain)
|
||||
@params.permit(:domain, :include_subdomains)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,9 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
|||
protected
|
||||
|
||||
def perform_total_query
|
||||
Status.joins(:account).merge(Account.where(domain: params[:domain])).count
|
||||
domain = params[:domain]
|
||||
domain = Instance.by_domain_and_subdomains(params[:domain]).select(:domain) if params[:include_subdomains]
|
||||
Status.joins(:account).merge(Account.where(domain: domain)).count
|
||||
end
|
||||
|
||||
def perform_previous_total_query
|
||||
|
@ -24,6 +26,14 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
|||
end
|
||||
|
||||
def perform_data_query
|
||||
account_matching_sql = begin
|
||||
if params[:include_subdomains]
|
||||
"accounts.domain IN (SELECT domain FROM instances WHERE reverse('.' || domain) LIKE reverse('.' || $5::text))"
|
||||
else
|
||||
'accounts.domain = $5::text'
|
||||
end
|
||||
end
|
||||
|
||||
sql = <<-SQL.squish
|
||||
SELECT axis.*, (
|
||||
WITH new_statuses AS (
|
||||
|
@ -31,7 +41,7 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
|||
FROM statuses
|
||||
INNER JOIN accounts ON accounts.id = statuses.account_id
|
||||
WHERE statuses.id BETWEEN $3 AND $4
|
||||
AND accounts.domain = $5::text
|
||||
AND #{account_matching_sql}
|
||||
AND date_trunc('day', statuses.created_at)::date = axis.period
|
||||
)
|
||||
SELECT count(*) FROM new_statuses
|
||||
|
@ -55,6 +65,6 @@ class Admin::Metrics::Measure::InstanceStatusesMeasure < Admin::Metrics::Measure
|
|||
end
|
||||
|
||||
def params
|
||||
@params.permit(:domain)
|
||||
@params.permit(:domain, :include_subdomains)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@ class EmojiFormatter
|
|||
# @param [Hash] options
|
||||
# @option options [Boolean] :animate
|
||||
# @option options [String] :style
|
||||
# @option options [String] :raw_shortcode
|
||||
def initialize(html, custom_emojis, options = {})
|
||||
raise ArgumentError unless html.html_safe?
|
||||
|
||||
|
@ -43,7 +44,7 @@ class EmojiFormatter
|
|||
next unless (char_after.nil? || !DISALLOWED_BOUNDING_REGEX.match?(char_after)) && (emoji = emoji_map[shortcode])
|
||||
|
||||
result << Nokogiri::XML::Text.new(text[last_index..shortname_start_index - 1], tree.document) if shortname_start_index.positive?
|
||||
result << Nokogiri::HTML.fragment(image_for_emoji(shortcode, emoji))
|
||||
result << Nokogiri::HTML.fragment(tag_for_emoji(shortcode, emoji))
|
||||
|
||||
last_index = i + 1
|
||||
elsif text[i] == ':' && (i.zero? || !DISALLOWED_BOUNDING_REGEX.match?(text[i - 1]))
|
||||
|
@ -78,7 +79,9 @@ class EmojiFormatter
|
|||
end
|
||||
end
|
||||
|
||||
def image_for_emoji(shortcode, emoji)
|
||||
def tag_for_emoji(shortcode, emoji)
|
||||
return content_tag(:span, ":#{shortcode}:", translate: 'no') if raw_shortcode?
|
||||
|
||||
original_url, static_url = emoji
|
||||
|
||||
image_tag(
|
||||
|
@ -106,4 +109,8 @@ class EmojiFormatter
|
|||
def animate?
|
||||
@options[:animate] || @options.key?(:style)
|
||||
end
|
||||
|
||||
def raw_shortcode?
|
||||
@options[:raw_shortcode]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class HashObject
|
||||
def initialize(hash)
|
||||
hash.each do |k, v|
|
||||
instance_variable_set("@#{k}", v)
|
||||
self.class.send(:define_method, k, proc { instance_variable_get("@#{k}") })
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Settings
|
||||
module Extend
|
||||
def settings
|
||||
@settings ||= ScopedSettings.new(self)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,8 +10,8 @@ class TranslationService::DeepL < TranslationService
|
|||
@api_key = api_key
|
||||
end
|
||||
|
||||
def translate(text, source_language, target_language)
|
||||
form = { text: text, source_lang: source_language&.upcase, target_lang: target_language, tag_handling: 'html' }
|
||||
def translate(texts, source_language, target_language)
|
||||
form = { text: texts, source_lang: source_language&.upcase, target_lang: target_language, tag_handling: 'html' }
|
||||
request(:post, '/v2/translate', form: form) do |res|
|
||||
transform_response(res.body_with_limit)
|
||||
end
|
||||
|
@ -67,12 +67,17 @@ class TranslationService::DeepL < TranslationService
|
|||
end
|
||||
end
|
||||
|
||||
def transform_response(str)
|
||||
json = Oj.load(str, mode: :strict)
|
||||
def transform_response(json)
|
||||
data = Oj.load(json, mode: :strict)
|
||||
raise UnexpectedResponseError unless data.is_a?(Hash)
|
||||
|
||||
raise UnexpectedResponseError unless json.is_a?(Hash)
|
||||
|
||||
Translation.new(text: json.dig('translations', 0, 'text'), detected_source_language: json.dig('translations', 0, 'detected_source_language')&.downcase, provider: 'DeepL.com')
|
||||
data['translations'].map do |translation|
|
||||
Translation.new(
|
||||
text: translation['text'],
|
||||
detected_source_language: translation['detected_source_language']&.downcase,
|
||||
provider: 'DeepL.com'
|
||||
)
|
||||
end
|
||||
rescue Oj::ParseError
|
||||
raise UnexpectedResponseError
|
||||
end
|
||||
|
|
|
@ -8,8 +8,8 @@ class TranslationService::LibreTranslate < TranslationService
|
|||
@api_key = api_key
|
||||
end
|
||||
|
||||
def translate(text, source_language, target_language)
|
||||
body = Oj.dump(q: text, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key)
|
||||
def translate(texts, source_language, target_language)
|
||||
body = Oj.dump(q: texts, source: source_language.presence || 'auto', target: target_language, format: 'html', api_key: @api_key)
|
||||
request(:post, '/translate', body: body) do |res|
|
||||
transform_response(res.body_with_limit, source_language)
|
||||
end
|
||||
|
@ -44,12 +44,17 @@ class TranslationService::LibreTranslate < TranslationService
|
|||
end
|
||||
end
|
||||
|
||||
def transform_response(str, source_language)
|
||||
json = Oj.load(str, mode: :strict)
|
||||
def transform_response(json, source_language)
|
||||
data = Oj.load(json, mode: :strict)
|
||||
raise UnexpectedResponseError unless data.is_a?(Hash)
|
||||
|
||||
raise UnexpectedResponseError unless json.is_a?(Hash)
|
||||
|
||||
Translation.new(text: json['translatedText'], detected_source_language: source_language, provider: 'LibreTranslate')
|
||||
data['translatedText'].map.with_index do |text, index|
|
||||
Translation.new(
|
||||
text: text,
|
||||
detected_source_language: data.dig('detectedLanguage', index, 'language') || source_language,
|
||||
provider: 'LibreTranslate'
|
||||
)
|
||||
end
|
||||
rescue Oj::ParseError
|
||||
raise UnexpectedResponseError
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue