Skip to content

Commit 0d8dd40

Browse files
Gargronhiyuki2578
authored andcommitted
Fix slow local timeline query (mastodon#11648)
Fix mastodon#11643
1 parent 88570d9 commit 0d8dd40

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class AddLocalIndexToStatuses < ActiveRecord::Migration[5.2]
2+
disable_ddl_transaction!
3+
4+
def up
5+
add_index :statuses, [:id, :account_id], name: :index_statuses_local_20190824, algorithm: :concurrently, order: { id: :desc }, where: '(local OR (uri IS NULL)) AND deleted_at IS NULL AND visibility = 0 AND reblog_of_id IS NULL AND ((NOT reply) OR (in_reply_to_account_id = account_id))'
6+
end
7+
8+
def down
9+
remove_index :statuses, name: :index_statuses_local_20190824
10+
end
11+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2019_08_20_003045) do
13+
ActiveRecord::Schema.define(version: 2019_08_23_221802) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -647,6 +647,7 @@
647647
t.bigint "poll_id"
648648
t.datetime "deleted_at"
649649
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
650+
t.index ["id", "account_id"], name: "index_statuses_local_20190824", order: { id: :desc }, where: "((local OR (uri IS NULL)) AND (deleted_at IS NULL) AND (visibility = 0) AND (reblog_of_id IS NULL) AND ((NOT reply) OR (in_reply_to_account_id = account_id)))"
650651
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
651652
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
652653
t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id"

0 commit comments

Comments
 (0)