rebake based on version, not date
This commit is contained in:
parent
91b6459f2b
commit
95221ee9c1
|
@ -15,9 +15,8 @@ class Post < ActiveRecord::Base
|
|||
include Trashable
|
||||
include HasCustomFields
|
||||
|
||||
# rebake all posts baked before this date
|
||||
# in our periodical job
|
||||
REBAKE_BEFORE = Time.new(2014,5,27)
|
||||
# increase this number to force a system wide post rebake
|
||||
BAKED_VERSION = 1
|
||||
|
||||
rate_limit
|
||||
rate_limit :limit_posts_per_day
|
||||
|
@ -315,7 +314,7 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.rebake_old(limit)
|
||||
Post.where('baked_at IS NULL OR baked_at < ?', REBAKE_BEFORE)
|
||||
Post.where('baked_version IS NULL OR baked_version < ?', BAKED_VERSION)
|
||||
.limit(limit).each do |p|
|
||||
begin
|
||||
p.rebake!
|
||||
|
@ -333,7 +332,7 @@ class Post < ActiveRecord::Base
|
|||
)
|
||||
old_cooked = cooked
|
||||
|
||||
update_columns(cooked: new_cooked, baked_at: Time.new)
|
||||
update_columns(cooked: new_cooked, baked_at: Time.new, baked_version: BAKED_VERSION)
|
||||
|
||||
# Extracts urls from the body
|
||||
TopicLink.extract_from self
|
||||
|
@ -391,6 +390,7 @@ class Post < ActiveRecord::Base
|
|||
self.last_editor_id ||= user_id
|
||||
self.cooked = cook(raw, topic_id: topic_id) unless new_record?
|
||||
self.baked_at = Time.new
|
||||
self.baked_version = BAKED_VERSION
|
||||
end
|
||||
|
||||
after_save do
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddBakedVersionToPost < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :posts, :baked_version, :integer
|
||||
end
|
||||
end
|
|
@ -834,11 +834,16 @@ describe Post do
|
|||
describe ".rebake_old" do
|
||||
it "will catch posts it needs to rebake" do
|
||||
post = create_post
|
||||
post.update_column(:baked_at, Time.new(2000,1,1))
|
||||
post.update_columns(baked_at: Time.new(2000,1,1), baked_version: -1)
|
||||
Post.rebake_old(100)
|
||||
|
||||
post.reload
|
||||
post.baked_at.should > 1.day.ago
|
||||
post.baked_at.should be > 1.day.ago
|
||||
|
||||
baked = post.baked_at
|
||||
Post.rebake_old(100)
|
||||
post.reload
|
||||
post.baked_at.should == baked
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue