mirror of
https://github.com/discourse/discourse.git
synced 2025-10-03 17:21:20 +08:00
- Add indexes in some places where we were seeing bottlenecks - Remove redundant ILIKE query --------- Co-authored-by: Gerhard Schlager <gerhard.schlager@discourse.org>
55 lines
1.7 KiB
Ruby
55 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
class AddJsonbIndexesToNotifications < ActiveRecord::Migration[7.2]
|
|
disable_ddl_transaction!
|
|
|
|
def up
|
|
execute <<~SQL
|
|
DROP INDEX CONCURRENTLY IF EXISTS index_notifications_on_data_original_username
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
CREATE INDEX CONCURRENTLY index_notifications_on_data_original_username
|
|
ON notifications ((data :: JSONB ->> 'original_username'))
|
|
WHERE (data :: JSONB ->> 'original_username') IS NOT NULL;
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
DROP INDEX CONCURRENTLY IF EXISTS index_notifications_on_data_display_username
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
CREATE INDEX CONCURRENTLY index_notifications_on_data_display_username
|
|
ON notifications ((data :: JSONB ->> 'display_username'))
|
|
WHERE (data :: JSONB ->> 'display_username') IS NOT NULL;
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
DROP INDEX CONCURRENTLY IF EXISTS index_notifications_on_data_username
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
CREATE INDEX CONCURRENTLY index_notifications_on_data_username
|
|
ON notifications ((data :: JSONB ->> 'username'))
|
|
WHERE (data :: JSONB ->> 'username') IS NOT NULL;
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
DROP INDEX CONCURRENTLY IF EXISTS index_notifications_on_data_username2
|
|
SQL
|
|
|
|
execute <<~SQL
|
|
CREATE INDEX CONCURRENTLY index_notifications_on_data_username2
|
|
ON notifications ((data :: JSONB ->> 'username2'))
|
|
WHERE (data :: JSONB ->> 'username2') IS NOT NULL;
|
|
SQL
|
|
end
|
|
|
|
def down
|
|
execute <<~SQL
|
|
DROP INDEX index_notifications_on_data_original_username;
|
|
DROP INDEX index_notifications_on_data_display_username;
|
|
DROP INDEX index_notifications_on_data_username;
|
|
DROP INDEX index_notifications_on_data_username2;
|
|
SQL
|
|
end
|
|
end
|