autocomplete: optimize searching by artist/wiki page other names.
Optimize searches for non-English phrases in autocomplete. These searches were pretty slow, and could sometimes cause sitewide lag spikes when users typed long strings of non-English text into the search box and caused an unintentional DoS. The trick is to use an `array_to_tsvector(other_names) USING gin` index on other_names. This supports fast string prefix matching against all elements of the array. The downside is that it doesn't allow infix or suffix matches, so we can't support wildcards in general. Wildcards didn't quite work anyway, since artist and wiki other names can contain literal '*' characters.
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
class AddArrayToTsvectorIndexOnWikiPagesAndArtists < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_index :wiki_pages, "array_to_tsvector(other_names)", using: :gin
|
||||
add_index :artists, "array_to_tsvector(other_names)", using: :gin
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user