summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-13 16:36:06 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-13 16:36:06 +0200
commite2705119ba718d40ff4f29c00027c2dfecef01ce (patch)
treec07151111c0bb956beae3d95afb6da115d31a980 /app
parentd96a61cbaed84a15c911bc49022b0d6d61992ee3 (diff)
wipe_draft!: add a grace period to the lock-with-no-draft branch
Its other two branches both require a day's inactivity before touching anything; this one didn't, so a lock acquired seconds ago with nothing drafted yet looked identical to one abandoned for a week -- confirmed with a throwaway script showing a lock cleared inside a single method call. Guarded on autosave.nil? specifically, since the method's first line already guarantees any autosave reaching this branch is a day old by construction.
Diffstat (limited to 'app')
-rw-r--r--app/models/node.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 535d8f1..73eefd1 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -249,12 +249,18 @@ class Node < ApplicationRecord
249 self 249 self
250 end 250 end
251 251
252 # removes a draft and the lock if it is older than a day and still 252 # Releases whatever's stale and abandoned; never anything actively in
253 # identical to head 253 # use. Three independent cases share one rule -- nothing is touched
254 # unless it's been sitting untouched for over a day:
255 # - a lock held with no draft or autosave at all (the editor opened
256 # the page and never actually wrote anything)
257 # - a fresh autosave older than a day, never promoted to a draft
258 # - a draft older than a day that's still identical to head
254 def wipe_draft! 259 def wipe_draft!
255 return if self.autosave && self.autosave.updated_at > 1.day.ago 260 return if self.autosave && self.autosave.updated_at > 1.day.ago
256 261
257 unless self.draft 262 unless self.draft
263 return if self.autosave.nil? && self.locked? && self.updated_at > 1.day.ago
258 self.autosave&.destroy 264 self.autosave&.destroy
259 self.autosave_id = nil 265 self.autosave_id = nil
260 self.unlock! 266 self.unlock!