From 02ed8c3783ca4d602cbfcc39d6df7dedd0460bc1 Mon Sep 17 00:00:00 2001 From: Peter Bhat Harkins Date: Thu, 30 Aug 2018 06:44:39 -0500 Subject: [PATCH] don't show replies on stories with negative scores --- ...5_update_replying_comments_to_version_7.rb | 5 +++ db/schema.rb | 4 +-- db/views/replying_comments_v07.sql | 36 +++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180830114325_update_replying_comments_to_version_7.rb create mode 100644 db/views/replying_comments_v07.sql diff --git a/db/migrate/20180830114325_update_replying_comments_to_version_7.rb b/db/migrate/20180830114325_update_replying_comments_to_version_7.rb new file mode 100644 index 00000000..3f965157 --- /dev/null +++ b/db/migrate/20180830114325_update_replying_comments_to_version_7.rb @@ -0,0 +1,5 @@ +class UpdateReplyingCommentsToVersion7 < ActiveRecord::Migration[5.0] + def change + update_view :replying_comments, version: 7, revert_to_version: 6 + end +end diff --git a/db/schema.rb b/db/schema.rb index d8481e41..e148277f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_07_11_123439) do +ActiveRecord::Schema.define(version: 2018_08_30_114325) do create_table "comments", id: :integer, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t| t.datetime "created_at", null: false @@ -264,7 +264,7 @@ ActiveRecord::Schema.define(version: 2018_07_11_123439) do create_view "replying_comments", sql_definition: <<-SQL - select `read_ribbons`.`user_id` AS `user_id`,`comments`.`id` AS `comment_id`,`read_ribbons`.`story_id` AS `story_id`,`comments`.`parent_comment_id` AS `parent_comment_id`,`comments`.`created_at` AS `comment_created_at`,`parent_comments`.`user_id` AS `parent_comment_author_id`,`comments`.`user_id` AS `comment_author_id`,`stories`.`user_id` AS `story_author_id`,(`read_ribbons`.`updated_at` < `comments`.`created_at`) AS `is_unread`,(select `votes`.`vote` from `votes` where ((`votes`.`user_id` = `read_ribbons`.`user_id`) and (`votes`.`comment_id` = `comments`.`id`))) AS `current_vote_vote`,(select `votes`.`reason` from `votes` where ((`votes`.`user_id` = `read_ribbons`.`user_id`) and (`votes`.`comment_id` = `comments`.`id`))) AS `current_vote_reason` from (((`read_ribbons` join `comments` on((`comments`.`story_id` = `read_ribbons`.`story_id`))) join `stories` on((`stories`.`id` = `comments`.`story_id`))) left join `comments` `parent_comments` on((`parent_comments`.`id` = `comments`.`parent_comment_id`))) where ((`read_ribbons`.`is_following` = 1) and (`comments`.`user_id` <> `read_ribbons`.`user_id`) and (`comments`.`is_deleted` = 0) and (`comments`.`is_moderated` = 0) and ((`parent_comments`.`user_id` = `read_ribbons`.`user_id`) or (isnull(`parent_comments`.`user_id`) and (`stories`.`user_id` = `read_ribbons`.`user_id`))) and ((`comments`.`upvotes` - `comments`.`downvotes`) >= 0) and (isnull(`parent_comments`.`id`) or ((`parent_comments`.`upvotes` - `parent_comments`.`downvotes`) >= 0))) + select `read_ribbons`.`user_id` AS `user_id`,`comments`.`id` AS `comment_id`,`read_ribbons`.`story_id` AS `story_id`,`comments`.`parent_comment_id` AS `parent_comment_id`,`comments`.`created_at` AS `comment_created_at`,`parent_comments`.`user_id` AS `parent_comment_author_id`,`comments`.`user_id` AS `comment_author_id`,`stories`.`user_id` AS `story_author_id`,(`read_ribbons`.`updated_at` < `comments`.`created_at`) AS `is_unread`,(select `votes`.`vote` from `votes` where ((`votes`.`user_id` = `read_ribbons`.`user_id`) and (`votes`.`comment_id` = `comments`.`id`))) AS `current_vote_vote`,(select `votes`.`reason` from `votes` where ((`votes`.`user_id` = `read_ribbons`.`user_id`) and (`votes`.`comment_id` = `comments`.`id`))) AS `current_vote_reason` from (((`read_ribbons` join `comments` on((`comments`.`story_id` = `read_ribbons`.`story_id`))) join `stories` on((`stories`.`id` = `comments`.`story_id`))) left join `comments` `parent_comments` on((`parent_comments`.`id` = `comments`.`parent_comment_id`))) where ((`read_ribbons`.`is_following` = 1) and (`comments`.`user_id` <> `read_ribbons`.`user_id`) and (`comments`.`is_deleted` = 0) and (`comments`.`is_moderated` = 0) and ((`parent_comments`.`user_id` = `read_ribbons`.`user_id`) or (isnull(`parent_comments`.`user_id`) and (`stories`.`user_id` = `read_ribbons`.`user_id`))) and ((`comments`.`upvotes` - `comments`.`downvotes`) >= 0) and (isnull(`parent_comments`.`id`) or ((`parent_comments`.`upvotes` - `parent_comments`.`downvotes`) >= 0)) and ((cast(`stories`.`upvotes` as signed) - cast(`stories`.`downvotes` as signed)) >= 0)) SQL end diff --git a/db/views/replying_comments_v07.sql b/db/views/replying_comments_v07.sql new file mode 100644 index 00000000..e301241d --- /dev/null +++ b/db/views/replying_comments_v07.sql @@ -0,0 +1,36 @@ +SELECT + read_ribbons.user_id, + comments.id as comment_id, + read_ribbons.story_id as story_id, + comments.parent_comment_id, + comments.created_at as comment_created_at, + parent_comments.user_id as parent_comment_author_id, + comments.user_id as comment_author_id, + stories.user_id as story_author_id, + (read_ribbons.updated_at < comments.created_at) as is_unread, + (select votes.vote from votes where votes.user_id = read_ribbons.user_id and votes.comment_id = comments.id) as current_vote_vote, + (select votes.reason from votes where votes.user_id = read_ribbons.user_id and votes.comment_id = comments.id) as current_vote_reason +FROM + read_ribbons +JOIN + comments ON comments.story_id = read_ribbons.story_id +JOIN + stories ON stories.id = comments.story_id +LEFT JOIN + comments parent_comments ON parent_comments.id = comments.parent_comment_id +WHERE + read_ribbons.is_following = 1 + AND comments.user_id != read_ribbons.user_id + AND comments.is_deleted = FALSE + AND comments.is_moderated = FALSE + AND + (parent_comments.user_id = read_ribbons.user_id + OR (parent_comments.user_id IS NULL + AND stories.user_id = read_ribbons.user_id)) + AND (comments.upvotes - comments.downvotes) >= 0 + AND ( + parent_comments.id IS NULL + OR (parent_comments.upvotes - parent_comments.downvotes) >= 0 + ) + AND (CAST(stories.upvotes as signed) - CAST(stories.downvotes as signed)) >= 0 +;