diff --git a/app/views/tag_subscriptions/index.html.erb b/app/views/tag_subscriptions/index.html.erb index 614f46e3b..950cd5bab 100644 --- a/app/views/tag_subscriptions/index.html.erb +++ b/app/views/tag_subscriptions/index.html.erb @@ -19,7 +19,7 @@ <%= link_to "edit", edit_tag_subscription_path(tag_subscription) %> | <%= link_to "delete", tag_subscription_path(tag_subscription), :method => :delete, :data => {:confirm => "Are you sure you want to delete this subscription?"} %> - | <%= link_to "posts", posts_path(:tags => "sub:#{tag_subscription.creator.name}:#{tag_subscription.name}") %> + | <%= link_to "posts", posts_path(:tags => "sub:#{tag_subscription.creator.name}:#{tag_subscription.name}"), :rel => "nofollow" %> <% end %> diff --git a/db/migrate/20160219004022_add_trigram_index_to_pools.rb b/db/migrate/20160219004022_add_trigram_index_to_pools.rb new file mode 100644 index 000000000..d8e847fd5 --- /dev/null +++ b/db/migrate/20160219004022_add_trigram_index_to_pools.rb @@ -0,0 +1,11 @@ +class AddTrigramIndexToPools < ActiveRecord::Migration + def up + execute "create extension pg_trgm" + execute "create index index_pools_on_name_trgm on pools using gin (name gin_trgm_ops)" + end + + def down + execute "drop index index_pools_on_name_trgm" + execute "drop extension pg_trgm" + end +end diff --git a/db/migrate/20160219010854_add_trigram_indexes_to_artists.rb b/db/migrate/20160219010854_add_trigram_indexes_to_artists.rb new file mode 100644 index 000000000..6f99cd9ab --- /dev/null +++ b/db/migrate/20160219010854_add_trigram_indexes_to_artists.rb @@ -0,0 +1,13 @@ +class AddTrigramIndexesToArtists < ActiveRecord::Migration + def up + execute "create index index_artists_on_name_trgm on artists using gin (name gin_trgm_ops)" + execute "create index index_artists_on_group_name_trgm on artists using gin (group_name gin_trgm_ops)" + execute "create index index_artists_on_other_names_trgm on artists using gin (other_names gin_trgm_ops)" + end + + def down + execute "drop index index_artists_on_other_names_trgm" + execute "drop index index_artists_on_group_name_trgm" + execute "drop index index_artists_on_name_trgm" + end +end diff --git a/db/scripts.sql b/db/scripts.sql index 764e84b84..1465c4010 100644 --- a/db/scripts.sql +++ b/db/scripts.sql @@ -78,7 +78,6 @@ SELECT 'table hit rate' AS name, sum(heap_blks_hit) / nullif(sum(heap_blks_hit) + sum(heap_blks_read),0) AS ratio FROM pg_statio_user_tables; -); -- index hit rate diff --git a/db/structure.sql b/db/structure.sql index d8ea7849f..a196a9229 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3,6 +3,7 @@ -- SET statement_timeout = 0; +SET lock_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SET check_function_bodies = false; @@ -22,6 +23,20 @@ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; +-- +-- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public; + + +-- +-- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams'; + + SET search_path = public, pg_catalog; -- @@ -421,8 +436,8 @@ CREATE TABLE advertisement_hits ( id integer NOT NULL, advertisement_id integer NOT NULL, ip_addr inet NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -459,8 +474,8 @@ CREATE TABLE advertisements ( height integer NOT NULL, file_name character varying(255) NOT NULL, is_work_safe boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -490,8 +505,8 @@ ALTER SEQUENCE advertisements_id_seq OWNED BY advertisements.id; CREATE TABLE amazon_backups ( id integer NOT NULL, last_id integer, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -557,8 +572,8 @@ CREATE TABLE artist_commentaries ( original_description text, translated_title text, translated_description text, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -594,8 +609,8 @@ CREATE TABLE artist_commentary_versions ( original_description text, translated_title text, translated_description text, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -627,8 +642,8 @@ CREATE TABLE artist_urls ( artist_id integer NOT NULL, url text NOT NULL, normalized_url text NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -666,8 +681,8 @@ CREATE TABLE artist_versions ( group_name character varying(255), url_string text, is_banned boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -703,8 +718,8 @@ CREATE TABLE artists ( other_names text, other_names_index tsvector, group_name character varying(255), - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -737,8 +752,8 @@ CREATE TABLE bans ( reason text NOT NULL, banner_id integer NOT NULL, expires_at timestamp without time zone NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -804,8 +819,8 @@ CREATE TABLE comment_votes ( comment_id integer NOT NULL, user_id integer NOT NULL, score integer NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -840,8 +855,8 @@ CREATE TABLE comments ( ip_addr inet NOT NULL, body_index tsvector NOT NULL, score integer DEFAULT 0 NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, updater_id integer, updater_ip_addr inet, do_not_bump_post boolean DEFAULT false NOT NULL, @@ -882,8 +897,8 @@ CREATE TABLE delayed_jobs ( locked_at timestamp without time zone, failed_at timestamp without time zone, locked_by character varying(255), - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, queue character varying(255) ); @@ -953,8 +968,8 @@ CREATE TABLE dmails ( message_index tsvector NOT NULL, is_read boolean DEFAULT false NOT NULL, is_deleted boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, creator_ip_addr inet DEFAULT '127.0.0.1'::inet NOT NULL ); @@ -2054,8 +2069,8 @@ CREATE TABLE forum_posts ( body text NOT NULL, text_index tsvector NOT NULL, is_deleted boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2157,8 +2172,8 @@ CREATE TABLE forum_topics ( is_locked boolean DEFAULT false NOT NULL, is_deleted boolean DEFAULT false NOT NULL, text_index tsvector NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, category_id integer DEFAULT 0 NOT NULL ); @@ -2191,8 +2206,8 @@ CREATE TABLE ip_bans ( creator_id integer NOT NULL, ip_addr inet NOT NULL, reason text NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2224,8 +2239,8 @@ CREATE TABLE janitor_trials ( creator_id integer NOT NULL, user_id integer NOT NULL, original_level integer, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, status character varying(255) DEFAULT 'active'::character varying NOT NULL ); @@ -2257,8 +2272,8 @@ CREATE TABLE key_values ( id integer NOT NULL, key character varying(255) NOT NULL, value text, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2289,8 +2304,8 @@ CREATE TABLE mod_actions ( id integer NOT NULL, creator_id integer NOT NULL, description text NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2322,8 +2337,8 @@ CREATE TABLE news_updates ( message text NOT NULL, creator_id integer NOT NULL, updater_id integer NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2362,8 +2377,8 @@ CREATE TABLE note_versions ( height integer NOT NULL, is_active boolean DEFAULT true NOT NULL, body text NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, version integer DEFAULT 0 NOT NULL ); @@ -2402,8 +2417,8 @@ CREATE TABLE notes ( is_active boolean DEFAULT true NOT NULL, body text NOT NULL, body_index tsvector NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, version integer DEFAULT 0 NOT NULL ); @@ -2468,8 +2483,8 @@ CREATE TABLE pool_versions ( post_ids text DEFAULT ''::text NOT NULL, updater_id integer NOT NULL, updater_ip_addr inet NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, name character varying(255) ); @@ -2506,8 +2521,8 @@ CREATE TABLE pools ( post_ids text DEFAULT ''::text NOT NULL, post_count integer DEFAULT 0 NOT NULL, is_deleted boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, category character varying(255) DEFAULT 'series'::character varying NOT NULL ); @@ -2541,8 +2556,8 @@ CREATE TABLE post_appeals ( creator_id integer NOT NULL, creator_ip_addr integer NOT NULL, reason text, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2573,8 +2588,8 @@ CREATE TABLE post_disapprovals ( id integer NOT NULL, user_id integer NOT NULL, post_id integer NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, reason character varying(255) DEFAULT 'legacy'::character varying, message text ); @@ -2610,8 +2625,8 @@ CREATE TABLE post_flags ( creator_ip_addr inet NOT NULL, reason text, is_resolved boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2640,8 +2655,8 @@ ALTER SEQUENCE post_flags_id_seq OWNED BY post_flags.id; CREATE TABLE post_versions ( id integer NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, post_id integer NOT NULL, tags text DEFAULT ''::text NOT NULL, rating character(1), @@ -2680,8 +2695,8 @@ CREATE TABLE post_votes ( post_id integer NOT NULL, user_id integer NOT NULL, score integer NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2710,8 +2725,8 @@ ALTER SEQUENCE post_votes_id_seq OWNED BY post_votes.id; CREATE TABLE posts ( id integer NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, up_score integer DEFAULT 0 NOT NULL, down_score integer DEFAULT 0 NOT NULL, score integer DEFAULT 0 NOT NULL, @@ -2827,8 +2842,8 @@ CREATE TABLE tag_aliases ( creator_ip_addr inet NOT NULL, forum_topic_id integer, status text DEFAULT 'pending'::text NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, post_count integer DEFAULT 0 NOT NULL ); @@ -2865,8 +2880,8 @@ CREATE TABLE tag_implications ( creator_ip_addr inet NOT NULL, forum_topic_id integer, status text DEFAULT 'pending'::text NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2902,8 +2917,8 @@ CREATE TABLE tag_subscriptions ( is_public boolean DEFAULT true NOT NULL, last_accessed_at timestamp without time zone, is_opted_in boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -2937,8 +2952,8 @@ CREATE TABLE tags ( category integer DEFAULT 0 NOT NULL, related_tags text, related_tags_updated_at timestamp without time zone, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, is_locked boolean DEFAULT false NOT NULL ); @@ -2971,8 +2986,8 @@ CREATE TABLE transaction_log_items ( category character varying(255), user_id integer, data text, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -3012,8 +3027,8 @@ CREATE TABLE uploads ( backtrace text, post_id integer, md5_confirmation character varying(255), - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, server text, parent_id integer ); @@ -3048,8 +3063,8 @@ CREATE TABLE user_feedback ( creator_id integer NOT NULL, category character varying(255) NOT NULL, body text NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -3085,8 +3100,8 @@ CREATE TABLE user_name_change_requests ( desired_name character varying(255), change_reason text, rejection_reason text, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -3117,8 +3132,8 @@ CREATE TABLE user_password_reset_nonces ( id integer NOT NULL, key character varying(255) NOT NULL, email character varying(255) NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL + created_at timestamp without time zone, + updated_at timestamp without time zone ); @@ -3147,8 +3162,8 @@ ALTER SEQUENCE user_password_reset_nonces_id_seq OWNED BY user_password_reset_no CREATE TABLE users ( id integer NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, name character varying(255) NOT NULL, password_hash character varying(255) NOT NULL, email character varying(255), @@ -3210,8 +3225,8 @@ CREATE TABLE wiki_page_versions ( title character varying(255) NOT NULL, body text NOT NULL, is_locked boolean NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, other_names text ); @@ -3246,8 +3261,8 @@ CREATE TABLE wiki_pages ( body text NOT NULL, body_index tsvector NOT NULL, is_locked boolean DEFAULT false NOT NULL, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, + created_at timestamp without time zone, + updated_at timestamp without time zone, updater_id integer, other_names text, other_names_index tsvector @@ -4851,10 +4866,10 @@ CREATE INDEX index_artist_versions_on_updater_id ON artist_versions USING btree -- --- Name: index_artists_on_group_name; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- Name: index_artists_on_group_name_trgm; Type: INDEX; Schema: public; Owner: -; Tablespace: -- -CREATE INDEX index_artists_on_group_name ON artists USING btree (group_name); +CREATE INDEX index_artists_on_group_name_trgm ON artists USING gin (group_name gin_trgm_ops); -- @@ -4864,6 +4879,13 @@ CREATE INDEX index_artists_on_group_name ON artists USING btree (group_name); CREATE UNIQUE INDEX index_artists_on_name ON artists USING btree (name); +-- +-- Name: index_artists_on_name_trgm; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX index_artists_on_name_trgm ON artists USING gin (name gin_trgm_ops); + + -- -- Name: index_artists_on_other_names_index; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -4871,6 +4893,13 @@ CREATE UNIQUE INDEX index_artists_on_name ON artists USING btree (name); CREATE INDEX index_artists_on_other_names_index ON artists USING gin (other_names_index); +-- +-- Name: index_artists_on_other_names_trgm; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX index_artists_on_other_names_trgm ON artists USING gin (other_names gin_trgm_ops); + + -- -- Name: index_bans_on_banner_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -6579,20 +6608,6 @@ CREATE INDEX index_pool_versions_on_updater_ip_addr ON pool_versions USING btree CREATE INDEX index_pools_on_creator_id ON pools USING btree (creator_id); --- --- Name: index_pools_on_lower_name; Type: INDEX; Schema: public; Owner: -; Tablespace: --- - -CREATE INDEX index_pools_on_lower_name ON pools USING btree (lower((name)::text)); - - --- --- Name: index_pools_on_name; Type: INDEX; Schema: public; Owner: -; Tablespace: --- - -CREATE INDEX index_pools_on_name ON pools USING btree (name); - - -- -- Name: index_post_appeals_on_creator_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -7285,3 +7300,7 @@ INSERT INTO schema_migrations (version) VALUES ('20150805010245'); INSERT INTO schema_migrations (version) VALUES ('20151217213321'); +INSERT INTO schema_migrations (version) VALUES ('20160219004022'); + +INSERT INTO schema_migrations (version) VALUES ('20160219010854'); +