fixes for source pattern search, fixed tests

This commit is contained in:
albert
2013-03-29 11:28:01 -04:00
parent 844a077599
commit 4f8cd6006c
5 changed files with 69 additions and 29 deletions

View File

@@ -1,24 +1,30 @@
class ChangeSourcePatternIndexOnPosts < ActiveRecord::Migration
def up
execute "set statement_timeout = 0"
execute "DROP INDEX index_posts_on_pixiv_suffix;"
execute "DROP INDEX index_posts_on_source_pattern;"
begin
execute "DROP INDEX index_posts_on_pixiv_suffix"
execute "DROP INDEX index_posts_on_source_pattern"
rescue Exception
end
execute "CREATE FUNCTION SourcePattern(src text) RETURNS text AS $$
BEGIN
RETURN regexp_replace(src, '^[^/]*(//)?[^/]*\.pixiv\.net/img.*(/[^/]*/[^/]*)$', 'pixiv\2');
RETURN regexp_replace(src, '^[^/]*(//)?[^/]*\.pixiv\.net/img.*(/[^/]*/[^/]*)$', E'pixiv\\\\2');
END;
$$ LANGUAGE plpgsql IMMUTABLE RETURNS NULL ON NULL INPUT;"
$$ LANGUAGE plpgsql IMMUTABLE RETURNS NULL ON NULL INPUT"
execute "CREATE INDEX index_posts_on_source_pattern ON posts USING btree
((SourcePattern(source)) text_pattern_ops);"
((SourcePattern(source)) text_pattern_ops)"
# execute "CREATE INDEX index_posts_on_pixiv_id ON posts USING btree
# ((substring(source, 'pixiv.net/img.*/([0-9]+)[^/]*$')::integer))"
end
def down
execute "set statement_timeout = 0"
execute "DROP INDEX index_posts_on_source_pattern;"
execute "DROP FUNCTION SourcePattern(text);"
execute "DROP INDEX index_posts_on_source_pattern"
execute "DROP FUNCTION SourcePattern(text)"
execute "CREATE INDEX index_posts_on_source_pattern ON posts USING btree
(source text_pattern_ops);"
(source text_pattern_ops)"
execute "CREATE INDEX index_posts_on_pixiv_suffix ON posts USING btree
((substring(source, 'pixiv.net/img.*/([^/]*/[^/]*)$')) text_pattern_ops);"
((substring(source, 'pixiv.net/img.*/([^/]*/[^/]*)$')) text_pattern_ops)"
# execute "DROP INDEX index_posts_on_pixiv_id"
end
end

View File

@@ -331,6 +331,19 @@ CREATE FUNCTION favorites_insert_trigger() RETURNS trigger
$$;
--
-- Name: sourcepattern(text); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION sourcepattern(src text) RETURNS text
LANGUAGE plpgsql IMMUTABLE STRICT
AS $_$
BEGIN
RETURN regexp_replace(src, '^[^/]*(//)?[^/]*.pixiv.net/img.*(/[^/]*/[^/]*)$', E'pixiv\\2');
END;
$_$;
--
-- Name: testprs_end(internal); Type: FUNCTION; Schema: public; Owner: -
--
@@ -5929,13 +5942,6 @@ CREATE INDEX index_posts_on_parent_id ON posts USING btree (parent_id);
CREATE INDEX index_posts_on_pixiv_id ON posts USING btree ((("substring"((source)::text, 'pixiv.net/img.*/([0-9]+)[^/]*$'::text))::integer));
--
-- Name: index_posts_on_pixiv_suffix; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_posts_on_pixiv_suffix ON posts USING btree ("substring"((source)::text, 'pixiv.net/img.*/([^/]*/[^/]*)$'::text) text_pattern_ops);
--
-- Name: index_posts_on_source; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
@@ -5947,7 +5953,7 @@ CREATE INDEX index_posts_on_source ON posts USING btree (source);
-- Name: index_posts_on_source_pattern; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_posts_on_source_pattern ON posts USING btree (source text_pattern_ops);
CREATE INDEX index_posts_on_source_pattern ON posts USING btree (sourcepattern((source)::text) text_pattern_ops);
--
@@ -6346,4 +6352,6 @@ INSERT INTO schema_migrations (version) VALUES ('20130322173859');
INSERT INTO schema_migrations (version) VALUES ('20130323160259');
INSERT INTO schema_migrations (version) VALUES ('20130326035904');
INSERT INTO schema_migrations (version) VALUES ('20130326035904');
INSERT INTO schema_migrations (version) VALUES ('20130328092739');