Fix order:comm and comment deletion for unbumped comments
fixes #1351, fixes #1352
This commit is contained in:
@@ -78,7 +78,7 @@ private
|
||||
end
|
||||
|
||||
def index_by_post
|
||||
@posts = Post.where("last_commented_at IS NOT NULL").tag_match(params[:tags]).reorder("last_commented_at DESC").paginate(params[:page], :limit => 5, :search_count => params[:search])
|
||||
@posts = Post.where("last_comment_bumped_at IS NOT NULL").tag_match(params[:tags]).reorder("last_comment_bumped_at DESC").paginate(params[:page], :limit => 5, :search_count => params[:search])
|
||||
@posts.all
|
||||
respond_with(@posts) do |format|
|
||||
format.html {render :action => "index_by_post"}
|
||||
|
||||
@@ -10,7 +10,6 @@ class Comment < ActiveRecord::Base
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_destroy :update_last_commented_at_on_destroy
|
||||
attr_accessible :body, :post_id, :do_not_bump_post
|
||||
attr_accessor :do_not_bump_post
|
||||
|
||||
module SearchMethods
|
||||
def recent
|
||||
@@ -140,8 +139,9 @@ class Comment < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def update_last_commented_at_on_create
|
||||
Post.update_all(["last_commented_at = ?", created_at], ["id = ?", post_id])
|
||||
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])
|
||||
Post.update_all(["last_comment_bumped_at = ?", created_at], ["id = ?", post_id])
|
||||
end
|
||||
true
|
||||
end
|
||||
@@ -153,11 +153,15 @@ class Comment < ActiveRecord::Base
|
||||
else
|
||||
Post.update_all(["last_commented_at = ?", other_comments.first.created_at], ["id = ?", post_id])
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
def do_not_bump_post?
|
||||
do_not_bump_post == "1"
|
||||
other_comments = other_comments.where("do_not_bump_post = FALSE")
|
||||
if other_comments.count == 0
|
||||
Post.update_all("last_comment_bumped_at = NULL", ["id = ?", post_id])
|
||||
else
|
||||
Post.update_all(["last_comment_bumped_at = ?", other_comments.first.created_at], ["id = ?", post_id])
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
class AddLastCommentBumpedAtToPosts < ActiveRecord::Migration
|
||||
def self.up
|
||||
execute "SET statement_timeout = 0"
|
||||
|
||||
rename_column :posts, :last_commented_at, :last_comment_bumped_at
|
||||
rename_index :posts, "index_posts_on_last_commented_at", "index_posts_on_last_comment_bumped_at"
|
||||
|
||||
add_column :posts, :last_commented_at, :datetime
|
||||
|
||||
Post.joins(:comments).uniq.find_each do |post|
|
||||
post.update_column(:last_commented_at, post.comments.last.created_at)
|
||||
end
|
||||
|
||||
add_column :comments, :do_not_bump_post, :boolean, :null => false, :default => false
|
||||
end
|
||||
|
||||
def self.down
|
||||
execute "SET statement_timeout = 0"
|
||||
|
||||
remove_column :posts, :last_commented_at
|
||||
|
||||
rename_column :posts, :last_comment_bumped_at, :last_commented_at
|
||||
rename_index :posts, "index_posts_on_last_comment_bumped_at", "index_posts_on_last_commented_at"
|
||||
|
||||
remove_column :comments, :do_not_bump_posts
|
||||
end
|
||||
end
|
||||
@@ -54,16 +54,16 @@ class CommentTest < ActiveSupport::TestCase
|
||||
|
||||
should "not bump the parent post" do
|
||||
post = FactoryGirl.create(:post)
|
||||
comment = FactoryGirl.create(:comment, :do_not_bump_post => "1", :post => post)
|
||||
comment = FactoryGirl.create(:comment, :do_not_bump_post => true, :post => post)
|
||||
post.reload
|
||||
assert_nil(post.last_commented_at)
|
||||
assert_nil(post.last_comment_bumped_at)
|
||||
|
||||
comment = FactoryGirl.create(:comment, :post => post)
|
||||
post.reload
|
||||
assert_not_nil(post.last_commented_at)
|
||||
assert_not_nil(post.last_comment_bumped_at)
|
||||
end
|
||||
|
||||
should "not update the post after exceeding the threshold" do
|
||||
should "not bump the post after exceeding the threshold" do
|
||||
Danbooru.config.stubs(:comment_threshold).returns(1)
|
||||
p = FactoryGirl.create(:post)
|
||||
c1 = FactoryGirl.create(:comment, :post => p)
|
||||
@@ -71,7 +71,22 @@ class CommentTest < ActiveSupport::TestCase
|
||||
c2 = FactoryGirl.create(:comment, :post => p)
|
||||
end
|
||||
p.reload
|
||||
assert_equal(c1.created_at.to_s, p.last_commented_at.to_s)
|
||||
assert_equal(c1.created_at.to_s, p.last_comment_bumped_at.to_s)
|
||||
end
|
||||
|
||||
should "always record the last_commented_at properly" do
|
||||
post = FactoryGirl.create(:post)
|
||||
Danbooru.config.stubs(:comment_threshold).returns(1)
|
||||
|
||||
c1 = FactoryGirl.create(:comment, :do_not_bump_post => true, :post => post)
|
||||
post.reload
|
||||
assert_equal(c1.created_at.to_s, post.last_commented_at.to_s)
|
||||
|
||||
Timecop.travel(2.seconds.from_now) do
|
||||
c2 = FactoryGirl.create(:comment, :post => post)
|
||||
post.reload
|
||||
assert_equal(c2.created_at.to_s, post.last_commented_at.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
should "not record the user id of the voter" do
|
||||
|
||||
Reference in New Issue
Block a user