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

@@ -6552,7 +6552,7 @@ CREATE INDEX index_pools_on_name ON public.pools USING btree (name);
-- Name: index_pools_on_name_trgm; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_pools_on_name_trgm ON public.pools USING gin (lower((name)::text) public.gin_trgm_ops);
CREATE INDEX index_pools_on_name_trgm ON public.pools USING gin (name public.gin_trgm_ops);
--
@@ -6769,7 +6769,7 @@ CREATE INDEX index_posts_on_pixiv_id ON public.posts USING btree (pixiv_id) WHER
-- Name: index_posts_on_source_trgm; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_posts_on_source_trgm ON public.posts USING gin (lower((source)::text) public.gin_trgm_ops) WHERE ((source)::text <> ''::text);
CREATE INDEX index_posts_on_source_trgm ON public.posts USING gin (source public.gin_trgm_ops);
--
@@ -7007,7 +7007,7 @@ CREATE UNIQUE INDEX index_users_on_name ON public.users USING btree (lower((name
-- Name: index_users_on_name_trgm; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_users_on_name_trgm ON public.users USING gin (lower((name)::text) public.gin_trgm_ops);
CREATE INDEX index_users_on_name_trgm ON public.users USING gin (name public.gin_trgm_ops);
--
@@ -7315,6 +7315,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190827234625'),
('20190828005453'),
('20190829052629'),
('20190829055758');
('20190829055758'),
('20190902224045');