From caf60d690df8e8ec8f9fdb09ea974c7b65612efd Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Mon, 28 Jan 2019 17:23:33 -0800 Subject: [PATCH] better check for forum post votability --- app/models/forum_post.rb | 4 +++- ...90129012253_add_tag_relationship_forum_post_indices.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190129012253_add_tag_relationship_forum_post_indices.rb diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index b885998ae..06ee93fe3 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -125,7 +125,9 @@ class ForumPost < ApplicationRecord end def votable? - body.to_s.match?(/->/) + TagAlias.where(forum_post_id: id).exists? || + TagImplication.where(forum_post_id: id).exists? || + BulkUpdateRequest.where(forum_post_id: id).exists? end def voted?(user, score) diff --git a/db/migrate/20190129012253_add_tag_relationship_forum_post_indices.rb b/db/migrate/20190129012253_add_tag_relationship_forum_post_indices.rb new file mode 100644 index 000000000..1d8fa8237 --- /dev/null +++ b/db/migrate/20190129012253_add_tag_relationship_forum_post_indices.rb @@ -0,0 +1,8 @@ +class AddTagRelationshipForumPostIndices < ActiveRecord::Migration[5.2] + def change + execute "set statement_timeout = 0" + add_index :tag_aliases, :forum_post_id + add_index :tag_implications, :forum_post_id + add_index :bulk_update_requests, :forum_post_id + end +end