Skip to content

Commit aa6b5b4

Browse files
authored
Fix slow local timeline query (#11648)
Fix #11643
1 parent 4190e31 commit aa6b5b4

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"
@@ -646,6 +646,7 @@
646646
t.bigint "poll_id"
647647
t.datetime "deleted_at"
648648
t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
649+
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)))"
649650
t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
650651
t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"
651652
t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id"

0 commit comments

Comments
 (0)