Fix timeouts in source:<url> searches and bookmarklet.

* Change the source index on posts from `(lower(source) gin_trgm_ops) WHERE source != ''`
  to just `(source gin_trgm_ops)`. The WHERE clause prevented the index
  from being used in source:<url> searches because we didn't specify
  the `source != ''` clause in the search itself. Excluding blank
  sources only saved a marginal amount of space anyway. This fixes
  timeouts in source:<url> searches and in the bookmarklet (since we do
  a source dupe check on the upload page too).

* Also switch from indexing `lower(name)` to `name` on pools and users.
  We don't need to lowercase the column because GIN indexes can be used
  with both LIKE and ILIKE queries.
This commit is contained in:
evazion
2019-09-02 18:53:27 -05:00
parent ffc693ef37
commit 5df3b01ca2
7 changed files with 44 additions and 11 deletions

View File

@@ -0,0 +1,23 @@
class FixTrigramIndexesOnLowerNames < ActiveRecord::Migration[6.0]
def up
remove_index :posts, name: "index_posts_on_source_trgm"
add_index :posts, "source gin_trgm_ops", name: "index_posts_on_source_trgm", using: :gin
remove_index :users, name: "index_users_on_name_trgm"
add_index :users, "name gin_trgm_ops", name: "index_users_on_name_trgm", using: :gin
remove_index :pools, name: "index_pools_on_name_trgm"
add_index :pools, "name gin_trgm_ops", name: "index_pools_on_name_trgm", using: :gin
end
def down
remove_index :posts, name: "index_posts_on_source_trgm"
add_index :posts, "lower(source) gin_trgm_ops", name: "index_posts_on_source_trgm", using: :gin, where: "source != ''"
remove_index :users, name: "index_users_on_name_trgm"
add_index :users, "lower(name) gin_trgm_ops", name: "index_users_on_name_trgm", using: :gin
remove_index :pools, name: "index_pools_on_name_trgm"
add_index :pools, "lower(name) gin_trgm_ops", name: "index_pools_on_name_trgm", using: :gin
end
end