From 64728c89d82a2439f28a5467e03fc25b2b8baf37 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 17 Nov 2019 14:14:17 -0600 Subject: [PATCH] db: remove tag_aliases.post_count column. This was only used in autocomplete, but it was unnecessary here because we could already get the post count from the tags table. --- app/logical/danbooru_maintenance.rb | 1 - app/models/tag.rb | 6 +++--- app/models/tag_alias.rb | 6 +----- ...20191117200404_drop_post_count_from_tag_aliases.rb | 6 ++++++ db/structure.sql | 11 ++--------- 5 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20191117200404_drop_post_count_from_tag_aliases.rb diff --git a/app/logical/danbooru_maintenance.rb b/app/logical/danbooru_maintenance.rb index d3c3a7751..07d1654a0 100644 --- a/app/logical/danbooru_maintenance.rb +++ b/app/logical/danbooru_maintenance.rb @@ -14,7 +14,6 @@ module DanbooruMaintenance Delayed::Job.where('created_at < ?', 45.days.ago).delete_all PostDisapproval.prune! ForumSubscription.process_all! - TagAlias.update_cached_post_counts_for_all PostDisapproval.dmail_messages! regenerate_post_counts! SuperVoter.init! diff --git a/app/models/tag.rb b/app/models/tag.rb index 4cc58717b..54cf39863 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -895,7 +895,7 @@ class Tag < ApplicationRecord q end - def names_matches_with_aliases(name, limit: 10) + def names_matches_with_aliases(name, limit) name = normalize_name(name) wildcard_name = name + '*' @@ -907,8 +907,8 @@ class Tag < ApplicationRecord .where("tag_aliases.antecedent_name LIKE ? ESCAPE E'\\\\'", wildcard_name.to_escaped_for_sql_like) .active .where("tags.name NOT LIKE ? ESCAPE E'\\\\'", wildcard_name.to_escaped_for_sql_like) - .where("tag_aliases.post_count > 0") - .order("tag_aliases.post_count desc") + .where("tags.post_count > 0") + .order("tags.post_count desc") .limit(limit * 2) # Get extra records in case some duplicates get filtered out. sql_query = "((#{query1.to_sql}) UNION ALL (#{query2.to_sql})) AS unioned_query" diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 14d63e153..bf1be4305 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -64,7 +64,7 @@ class TagAlias < TagRelationship update_posts forum_updater.update(approval_message(approver), "APPROVED") if update_topic rename_wiki_and_artist - update(status: "active", post_count: consequent_tag.post_count) + update(status: "active") end rescue Exception => e if tries < 5 @@ -183,10 +183,6 @@ class TagAlias < TagRelationship end end - def self.update_cached_post_counts_for_all - execute_sql("UPDATE tag_aliases SET post_count = tags.post_count FROM tags WHERE tags.name = tag_aliases.consequent_name") - end - def create_mod_action alias_desc = %Q("tag alias ##{id}":[#{Rails.application.routes.url_helpers.tag_alias_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]]) diff --git a/db/migrate/20191117200404_drop_post_count_from_tag_aliases.rb b/db/migrate/20191117200404_drop_post_count_from_tag_aliases.rb new file mode 100644 index 000000000..928bc1b81 --- /dev/null +++ b/db/migrate/20191117200404_drop_post_count_from_tag_aliases.rb @@ -0,0 +1,6 @@ +class DropPostCountFromTagAliases < ActiveRecord::Migration[6.0] + def change + remove_index :tag_aliases, :post_count + remove_column :tag_aliases, :post_count, :integer, null: false, default: 0 + end +end diff --git a/db/structure.sql b/db/structure.sql index fcb9c9a0d..d5d5acad3 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2887,7 +2887,6 @@ CREATE TABLE public.tag_aliases ( status text DEFAULT 'pending'::text NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - post_count integer DEFAULT 0 NOT NULL, approver_id integer, forum_post_id integer ); @@ -6901,13 +6900,6 @@ CREATE INDEX index_tag_aliases_on_consequent_name ON public.tag_aliases USING bt CREATE INDEX index_tag_aliases_on_forum_post_id ON public.tag_aliases USING btree (forum_post_id); --- --- Name: index_tag_aliases_on_post_count; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_tag_aliases_on_post_count ON public.tag_aliases USING btree (post_count); - - -- -- Name: index_tag_implications_on_antecedent_name; Type: INDEX; Schema: public; Owner: - -- @@ -7404,6 +7396,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191116224228'), ('20191117074642'), ('20191117080647'), -('20191117081229'); +('20191117081229'), +('20191117200404');