@statuses = @account.statuses.where(visibility: [:public, :unlisted])
if params[:media]
- @statuses.merge!(Status.joins(:media_attachments).group(:id))
+ @statuses.merge!(Status.joins(:media_attachments).merge(@account.media_attachments.reorder(nil)).group(:id))
end
@statuses = @statuses.preload(:media_attachments, :mentions).page(params[:page]).per(PER_PAGE)
--- /dev/null
+class AddIndexOnMediaAttachmentsAccountIdStatusId < ActiveRecord::Migration[5.2]
+ disable_ddl_transaction!
+
+ def up
+ add_index :media_attachments, [:account_id, :status_id], order: { status_id: :desc }, algorithm: :concurrently
+ remove_index :media_attachments, :account_id, algorithm: :concurrently
+ end
+
+ def down
+ add_index :media_attachments, :account_id, algorithm: :concurrently
+ remove_index :media_attachments, [:account_id, :status_id], order: { status_id: :desc }, algorithm: :concurrently
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2021_04_21_121431) do
+ActiveRecord::Schema.define(version: 2021_04_25_135952) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.integer "thumbnail_file_size"
t.datetime "thumbnail_updated_at"
t.string "thumbnail_remote_url"
- t.index ["account_id"], name: "index_media_attachments_on_account_id"
+ t.index ["account_id", "status_id"], name: "index_media_attachments_on_account_id_and_status_id", order: { status_id: :desc }
t.index ["scheduled_status_id"], name: "index_media_attachments_on_scheduled_status_id"
t.index ["shortcode"], name: "index_media_attachments_on_shortcode", unique: true
t.index ["status_id"], name: "index_media_attachments_on_status_id"