DEV: correct revision debouncer for backup draft

DEV: correct revision debouncer for backup draft

We were debouncing on update_at which we kept on pushing forward, this was leading to not enough revisions.

diff --git a/app/models/draft.rb b/app/models/draft.rb
index 287d25c263..f05cb8b7fe 100644
--- a/app/models/draft.rb
+++ b/app/models/draft.rb
@@ -137,7 +137,7 @@ class Draft < ActiveRecord::Base
         ).create
         BackupDraftPost.create!(user_id: user.id, key: key, post_id: post.id)
       end
-    elsif post.updated_at > 5.minutes.ago
+    elsif post.last_version_at > 5.minutes.ago
       # bypass all validations here to maximize speed
       post.update_columns(
         raw: draft_body,
diff --git a/spec/models/draft_spec.rb b/spec/models/draft_spec.rb
index b65c20c3b7..fff8b8d579 100644
--- a/spec/models/draft_spec.rb
+++ b/spec/models/draft_spec.rb
@@ -19,13 +19,17 @@ describe Draft do
 
       Draft.set(user, "new_private_message", 0, draft.to_json)
       draft["reply"] = "test" * 100
+
+      half_grace = (SiteSetting.editing_grace_period / 2 + 1).seconds
+
+      freeze_time half_grace.from_now
       Draft.set(user, "new_private_message", 77, draft.to_json)
 
       draft_post = BackupDraftPost.find_by(user_id: user.id, key: "new_private_message").post
 
       expect(draft_post.revisions.count).to eq(0)
 
-      freeze_time 10.minutes.from_now
+      freeze_time half_grace.from_now
 
       # this should trigger a post revision as 10 minutes have passed
       draft["reply"] = "hello"

GitHub sha: cb044379

1 Like