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:
@@ -4898,6 +4898,13 @@ CREATE INDEX index_artist_versions_on_updater_id ON public.artist_versions USING
|
||||
CREATE INDEX index_artist_versions_on_updater_ip_addr ON public.artist_versions USING btree (updater_ip_addr);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_artists_on_array_to_tsvector_other_names; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_artists_on_array_to_tsvector_other_names ON public.artists USING gin (array_to_tsvector(other_names));
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_artists_on_group_name; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -7535,6 +7542,13 @@ CREATE INDEX index_wiki_page_versions_on_updater_ip_addr ON public.wiki_page_ver
|
||||
CREATE INDEX index_wiki_page_versions_on_wiki_page_id ON public.wiki_page_versions USING btree (wiki_page_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_wiki_pages_on_array_to_tsvector_other_names; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_wiki_pages_on_array_to_tsvector_other_names ON public.wiki_pages USING gin (array_to_tsvector(other_names));
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_wiki_pages_on_body_index_index; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -7870,6 +7884,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20210108030722'),
|
||||
('20210108030723'),
|
||||
('20210108030724'),
|
||||
('20210110015410');
|
||||
('20210110015410'),
|
||||
('20210110090656');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user