diff --git a/app/lib/emoji_formatter.rb b/app/lib/emoji_formatter.rb index c193df9bb65..05f776c4fa2 100644 --- a/app/lib/emoji_formatter.rb +++ b/app/lib/emoji_formatter.rb @@ -71,7 +71,7 @@ class EmojiFormatter private def emoji_map - @emoji_map ||= custom_emojis.each_with_object({}) { |e, h| h[e.shortcode] = [full_asset_url(e.image.url), full_asset_url(e.image.url(:static))] } + @emoji_map ||= custom_emojis.to_h { |e| [e.shortcode, [full_asset_url(e.image.url), full_asset_url(e.image.url(:static))]] } end def tag_for_emoji(shortcode, emoji) diff --git a/app/lib/importer/base_importer.rb b/app/lib/importer/base_importer.rb index 7688426b48c..679e3a5198d 100644 --- a/app/lib/importer/base_importer.rb +++ b/app/lib/importer/base_importer.rb @@ -51,7 +51,7 @@ class Importer::BaseImporter raise ActiveRecord::UnknownPrimaryKey, index.adapter.target if primary_key.nil? ids = documents.pluck('_id') - existence_map = index.adapter.target.where(primary_key => ids).pluck(primary_key).each_with_object({}) { |id, map| map[id.to_s] = true } + existence_map = index.adapter.target.where(primary_key => ids).pluck(primary_key).to_h { |id| [id.to_s, true] } tmp = ids.reject { |id| existence_map[id] } next if tmp.empty? diff --git a/app/models/concerns/account/mappings.rb b/app/models/concerns/account/mappings.rb index b44ff9c844a..76c0f64a1c8 100644 --- a/app/models/concerns/account/mappings.rb +++ b/app/models/concerns/account/mappings.rb @@ -5,12 +5,12 @@ module Account::Mappings class_methods do def following_map(target_account_ids, account_id) - Follow.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |follow, mapping| - mapping[follow.target_account_id] = { + Follow.where(target_account_id: target_account_ids, account_id: account_id).to_h do |follow| + [follow.target_account_id, { reblogs: follow.show_reblogs?, notify: follow.notify?, languages: follow.languages, - } + }] end end @@ -36,21 +36,21 @@ module Account::Mappings end def muting_map(target_account_ids, account_id) - Mute.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |mute, mapping| - mapping[mute.target_account_id] = { + Mute.where(target_account_id: target_account_ids, account_id: account_id).to_h do |mute| + [mute.target_account_id, { notifications: mute.hide_notifications?, expires_at: mute.expires_at, - } + }] end end def requested_map(target_account_ids, account_id) - FollowRequest.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |follow_request, mapping| - mapping[follow_request.target_account_id] = { + FollowRequest.where(target_account_id: target_account_ids, account_id: account_id).to_h do |follow_request| + [follow_request.target_account_id, { reblogs: follow_request.show_reblogs?, notify: follow_request.notify?, languages: follow_request.languages, - } + }] end end @@ -69,10 +69,10 @@ module Account::Mappings end def account_note_map(target_account_ids, account_id) - AccountNote.where(target_account_id: target_account_ids, account_id: account_id).each_with_object({}) do |note, mapping| - mapping[note.target_account_id] = { + AccountNote.where(target_account_id: target_account_ids, account_id: account_id).to_h do |note| + [note.target_account_id, { comment: note.comment, - } + }] end end diff --git a/app/models/status.rb b/app/models/status.rb index 2b5f8e58a3c..d5cfe2df681 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -362,7 +362,7 @@ class Status < ApplicationRecord class << self def favourites_map(status_ids, account_id) - Favourite.select(:status_id).where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |f, h| h[f.status_id] = true } + Favourite.select(:status_id).where(status_id: status_ids).where(account_id: account_id).to_h { |f| [f.status_id, true] } end def bookmarks_map(status_ids, account_id) @@ -370,15 +370,15 @@ class Status < ApplicationRecord end def reblogs_map(status_ids, account_id) - unscoped.select(:reblog_of_id).where(reblog_of_id: status_ids).where(account_id: account_id).each_with_object({}) { |s, h| h[s.reblog_of_id] = true } + unscoped.select(:reblog_of_id).where(reblog_of_id: status_ids).where(account_id: account_id).to_h { |s| [s.reblog_of_id, true] } end def mutes_map(conversation_ids, account_id) - ConversationMute.select(:conversation_id).where(conversation_id: conversation_ids).where(account_id: account_id).each_with_object({}) { |m, h| h[m.conversation_id] = true } + ConversationMute.select(:conversation_id).where(conversation_id: conversation_ids).where(account_id: account_id).to_h { |m| [m.conversation_id, true] } end def pins_map(status_ids, account_id) - StatusPin.select(:status_id).where(status_id: status_ids).where(account_id: account_id).each_with_object({}) { |p, h| h[p.status_id] = true } + StatusPin.select(:status_id).where(status_id: status_ids).where(account_id: account_id).to_h { |p| [p.status_id, true] } end def from_text(text) diff --git a/app/presenters/account_relationships_presenter.rb b/app/presenters/account_relationships_presenter.rb index f06aeb86741..d924e1f2a31 100644 --- a/app/presenters/account_relationships_presenter.rb +++ b/app/presenters/account_relationships_presenter.rb @@ -60,7 +60,7 @@ class AccountRelationshipsPresenter Rails.cache.write_multi(to_cache, expires_in: 1.day) # Return formatted value - @accounts.each_with_object({}) { |account, h| h[account.id] = blocks_by_domain[account.domain] } + @accounts.to_h { |account| [account.id, blocks_by_domain[account.domain]] } end def cached diff --git a/app/presenters/tag_relationships_presenter.rb b/app/presenters/tag_relationships_presenter.rb index 922eb7a39ba..669b3588625 100644 --- a/app/presenters/tag_relationships_presenter.rb +++ b/app/presenters/tag_relationships_presenter.rb @@ -8,8 +8,8 @@ class TagRelationshipsPresenter @following_map = {} @featuring_map = {} else - @following_map = TagFollow.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).each_with_object({}) { |f, h| h[f.tag_id] = true }.merge(options[:following_map] || {}) - @featuring_map = FeaturedTag.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).each_with_object({}) { |f, h| h[f.tag_id] = true }.merge(options[:featuring_map] || {}) + @following_map = TagFollow.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).to_h { |f| [f.tag_id, true] }.merge(options[:following_map] || {}) + @featuring_map = FeaturedTag.select(:tag_id).where(tag_id: tags.map(&:id), account_id: current_account_id).to_h { |f| [f.tag_id, true] }.merge(options[:featuring_map] || {}) end end end