0
0
Fork 0

Improve various queries against account domains (#25126)

This commit is contained in:
Claire 2023-05-25 09:27:16 +02:00 committed by GitHub
parent e58c36d308
commit 1d588d58f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 3 deletions

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class AddIndexAccountsOnDomainAndId < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :accounts, [:domain, :id], name: :index_accounts_on_domain_and_id, algorithm: :concurrently
end
end

View file

@ -0,0 +1,13 @@
# frozen_string_literal: true
class FixAccountDomainCasing < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
safety_assured do
execute 'UPDATE accounts SET domain = lower(domain) WHERE domain IS NOT NULL AND domain != lower(domain)'
end
end
def down; end
end

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class AddIndexInstancesOnReverseDomain < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def change
add_index :instances, "reverse('.' || domain), domain", name: :index_instances_on_reverse_domain, algorithm: :concurrently
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2023_03_30_155710) do
ActiveRecord::Schema.define(version: 2023_05_24_194155) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -188,6 +188,7 @@ ActiveRecord::Schema.define(version: 2023_03_30_155710) do
t.datetime "requested_review_at"
t.index "(((setweight(to_tsvector('simple'::regconfig, (display_name)::text), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, (username)::text), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(domain, ''::character varying))::text), 'C'::\"char\")))", name: "search_index", using: :gin
t.index "lower((username)::text), COALESCE(lower((domain)::text), ''::text)", name: "index_accounts_on_username_and_domain_lower", unique: true
t.index ["domain", "id"], name: "index_accounts_on_domain_and_id"
t.index ["moved_to_account_id"], name: "index_accounts_on_moved_to_account_id", where: "(moved_to_account_id IS NOT NULL)"
t.index ["uri"], name: "index_accounts_on_uri"
t.index ["url"], name: "index_accounts_on_url", opclass: :text_pattern_ops, where: "(url IS NOT NULL)"
@ -1283,6 +1284,7 @@ ActiveRecord::Schema.define(version: 2023_03_30_155710) do
FROM (domain_allows
LEFT JOIN domain_counts ON (((domain_counts.domain)::text = (domain_allows.domain)::text)));
SQL
add_index "instances", "reverse(('.'::text || (domain)::text)), domain", name: "index_instances_on_reverse_domain"
add_index "instances", ["domain"], name: "index_instances_on_domain", unique: true
create_view "user_ips", sql_definition: <<-SQL