about summary refs log tree commit diff
path: root/app/lib/admin/metrics/dimension/instance_languages_dimension.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-03-10 17:29:15 +0100
committerGitHub <noreply@github.com>2022-03-10 17:29:15 +0100
commit2c8bb1745359a3bf200d37383dc56d5951e2b6bc (patch)
tree6b22f1ab7e96c9223760de2a74dc1d4d985f7758 /app/lib/admin/metrics/dimension/instance_languages_dimension.rb
parent02133866e6915e37431298b396e1aded1e4c44c5 (diff)
parent43bce02a7ae78954be8857f547434c56ac59fa59 (diff)
Merge pull request #1715 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/lib/admin/metrics/dimension/instance_languages_dimension.rb')
-rw-r--r--app/lib/admin/metrics/dimension/instance_languages_dimension.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/lib/admin/metrics/dimension/instance_languages_dimension.rb b/app/lib/admin/metrics/dimension/instance_languages_dimension.rb
new file mode 100644
index 000000000..1ede1a56e
--- /dev/null
+++ b/app/lib/admin/metrics/dimension/instance_languages_dimension.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+class Admin::Metrics::Dimension::InstanceLanguagesDimension < Admin::Metrics::Dimension::BaseDimension
+  include LanguagesHelper
+
+  def self.with_params?
+    true
+  end
+
+  def key
+    'instance_languages'
+  end
+
+  protected
+
+  def perform_query
+    sql = <<-SQL.squish
+      SELECT COALESCE(statuses.language, 'und') AS language, count(*) AS value
+      FROM statuses
+      INNER JOIN accounts ON accounts.id = statuses.account_id
+      WHERE accounts.domain = $1
+        AND statuses.id BETWEEN $2 AND $3
+        AND statuses.reblog_of_id IS NULL
+      GROUP BY COALESCE(statuses.language, 'und')
+      ORDER BY count(*) DESC
+      LIMIT $4
+    SQL
+
+    rows = ActiveRecord::Base.connection.select_all(sql, nil, [[nil, params[:domain]], [nil, Mastodon::Snowflake.id_at(@start_at, with_random: false)], [nil, Mastodon::Snowflake.id_at(@end_at, with_random: false)], [nil, @limit]])
+
+    rows.map { |row| { key: row['language'], human_key: standard_locale_name(row['language']), value: row['value'].to_s } }
+  end
+
+  def params
+    @params.permit(:domain)
+  end
+end