Extract ExportSummary
class for account object counts (#32227)
This commit is contained in:
parent
52afa94f1c
commit
d95f6f4410
6 changed files with 177 additions and 117 deletions
|
@ -9,7 +9,7 @@ class Settings::ExportsController < Settings::BaseController
|
|||
skip_before_action :require_functional!
|
||||
|
||||
def show
|
||||
@export = Export.new(current_account)
|
||||
@export_summary = ExportSummary.new(preloaded_account)
|
||||
@backups = current_user.backups
|
||||
end
|
||||
|
||||
|
@ -25,4 +25,15 @@ class Settings::ExportsController < Settings::BaseController
|
|||
|
||||
redirect_to settings_export_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def preloaded_account
|
||||
current_account.tap do |account|
|
||||
ActiveRecord::Associations::Preloader.new(
|
||||
records: [account],
|
||||
associations: :account_stat
|
||||
).call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,42 +55,6 @@ class Export
|
|||
end
|
||||
end
|
||||
|
||||
def total_storage
|
||||
account.media_attachments.sum(:file_file_size)
|
||||
end
|
||||
|
||||
def total_statuses
|
||||
account.statuses_count
|
||||
end
|
||||
|
||||
def total_bookmarks
|
||||
account.bookmarks.count
|
||||
end
|
||||
|
||||
def total_follows
|
||||
account.following_count
|
||||
end
|
||||
|
||||
def total_lists
|
||||
account.owned_lists.count
|
||||
end
|
||||
|
||||
def total_followers
|
||||
account.followers_count
|
||||
end
|
||||
|
||||
def total_blocks
|
||||
account.blocking.count
|
||||
end
|
||||
|
||||
def total_mutes
|
||||
account.muting.count
|
||||
end
|
||||
|
||||
def total_domain_blocks
|
||||
account.domain_blocks.count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def to_csv(accounts)
|
||||
|
|
70
app/presenters/export_summary.rb
Normal file
70
app/presenters/export_summary.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ExportSummary
|
||||
attr_reader :account, :counts
|
||||
|
||||
delegate(
|
||||
:blocking,
|
||||
:bookmarks,
|
||||
:domain_blocks,
|
||||
:owned_lists,
|
||||
:media_attachments,
|
||||
:muting,
|
||||
to: :account,
|
||||
prefix: true
|
||||
)
|
||||
|
||||
def initialize(account)
|
||||
@account = account
|
||||
@counts = populate_counts
|
||||
end
|
||||
|
||||
def total_blocks
|
||||
counts[:blocks].value
|
||||
end
|
||||
|
||||
def total_bookmarks
|
||||
counts[:bookmarks].value
|
||||
end
|
||||
|
||||
def total_domain_blocks
|
||||
counts[:domain_blocks].value
|
||||
end
|
||||
|
||||
def total_followers
|
||||
account.followers_count
|
||||
end
|
||||
|
||||
def total_follows
|
||||
account.following_count
|
||||
end
|
||||
|
||||
def total_lists
|
||||
counts[:owned_lists].value
|
||||
end
|
||||
|
||||
def total_mutes
|
||||
counts[:muting].value
|
||||
end
|
||||
|
||||
def total_statuses
|
||||
account.statuses_count
|
||||
end
|
||||
|
||||
def total_storage
|
||||
counts[:storage].value
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def populate_counts
|
||||
{
|
||||
blocks: account_blocking.async_count,
|
||||
bookmarks: account_bookmarks.async_count,
|
||||
domain_blocks: account_domain_blocks.async_count,
|
||||
owned_lists: account_owned_lists.async_count,
|
||||
muting: account_muting.async_count,
|
||||
storage: account_media_attachments.async_sum(:file_file_size),
|
||||
}
|
||||
end
|
||||
end
|
|
@ -6,39 +6,39 @@
|
|||
%tbody
|
||||
%tr
|
||||
%th= t('exports.storage')
|
||||
%td= number_to_human_size @export.total_storage
|
||||
%td= number_to_human_size @export_summary.total_storage
|
||||
%td
|
||||
%tr
|
||||
%th= t('accounts.posts_tab_heading')
|
||||
%td= number_with_delimiter @export.total_statuses
|
||||
%td= number_with_delimiter @export_summary.total_statuses
|
||||
%td
|
||||
%tr
|
||||
%th= t('admin.accounts.follows')
|
||||
%td= number_with_delimiter @export.total_follows
|
||||
%td= number_with_delimiter @export_summary.total_follows
|
||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_follows_path(format: :csv)
|
||||
%tr
|
||||
%th= t('exports.lists')
|
||||
%td= number_with_delimiter @export.total_lists
|
||||
%td= number_with_delimiter @export_summary.total_lists
|
||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_lists_path(format: :csv)
|
||||
%tr
|
||||
%th= t('admin.accounts.followers')
|
||||
%td= number_with_delimiter @export.total_followers
|
||||
%td= number_with_delimiter @export_summary.total_followers
|
||||
%td
|
||||
%tr
|
||||
%th= t('exports.mutes')
|
||||
%td= number_with_delimiter @export.total_mutes
|
||||
%td= number_with_delimiter @export_summary.total_mutes
|
||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_mutes_path(format: :csv)
|
||||
%tr
|
||||
%th= t('exports.blocks')
|
||||
%td= number_with_delimiter @export.total_blocks
|
||||
%td= number_with_delimiter @export_summary.total_blocks
|
||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_blocks_path(format: :csv)
|
||||
%tr
|
||||
%th= t('exports.domain_blocks')
|
||||
%td= number_with_delimiter @export.total_domain_blocks
|
||||
%td= number_with_delimiter @export_summary.total_domain_blocks
|
||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_domain_blocks_path(format: :csv)
|
||||
%tr
|
||||
%th= t('exports.bookmarks')
|
||||
%td= number_with_delimiter @export.total_bookmarks
|
||||
%td= number_with_delimiter @export_summary.total_bookmarks
|
||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_bookmarks_path(format: :csv)
|
||||
|
||||
%hr.spacer/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue