From 4def5b22fbf1bcdd6b142f04657e8e51e3d66afc Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 5 Apr 2013 12:52:15 -0400 Subject: [PATCH 1/3] fixes #1194 --- app/models/comment.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index f1158bd4e..74701a14b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,5 @@ class Comment < ActiveRecord::Base - validate :validate_creator_is_not_limited + validate :validate_creator_is_not_limited, :on => :create validates_format_of :body, :with => /\S/, :message => 'has no content' belongs_to :post belongs_to :creator, :class_name => "User" From f7fa452d88db8174dacfff08442161c5a7534ed2 Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 5 Apr 2013 13:09:45 -0400 Subject: [PATCH 2/3] fixes #1200 --- app/models/comment.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 74701a14b..213907387 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -102,8 +102,11 @@ class Comment < ActiveRecord::Base end def update_last_commented_at_on_destroy - if Comment.where("post_id = ? and id <> ?", post_id, id).count == 0 + other_comments = Comment.where("post_id = ? and id <> ?", post_id, id).order("id DESC") + if other_comments.count == 0 Post.update_all("last_commented_at = NULL", ["id = ?", post_id]) + else + Post.update_all(["last_commented_at = ?", other_comments.first.created_at], ["id = ?", post_id]) end true end From 90513d89ce84a2d19cfd030757325fe530d8915f Mon Sep 17 00:00:00 2001 From: Toks Date: Fri, 5 Apr 2013 13:10:55 -0400 Subject: [PATCH 3/3] swap method location for neatness --- app/models/comment.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 213907387..a2973cf22 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -101,6 +101,13 @@ class Comment < ActiveRecord::Base end end + def update_last_commented_at_on_create + if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post? + Post.update_all(["last_commented_at = ?", created_at], ["id = ?", post_id]) + end + true + end + def update_last_commented_at_on_destroy other_comments = Comment.where("post_id = ? and id <> ?", post_id, id).order("id DESC") if other_comments.count == 0 @@ -111,13 +118,6 @@ class Comment < ActiveRecord::Base true end - def update_last_commented_at_on_create - if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post? - Post.update_all(["last_commented_at = ?", created_at], ["id = ?", post_id]) - end - true - end - def do_not_bump_post? do_not_bump_post == "1" end