From e2705119ba718d40ff4f29c00027c2dfecef01ce Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 13 Jul 2026 16:36:06 +0200 Subject: 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. --- app/models/node.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'app/models/node.rb') 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 self end - # removes a draft and the lock if it is older than a day and still - # identical to head + # Releases whatever's stale and abandoned; never anything actively in + # use. Three independent cases share one rule -- nothing is touched + # unless it's been sitting untouched for over a day: + # - a lock held with no draft or autosave at all (the editor opened + # the page and never actually wrote anything) + # - a fresh autosave older than a day, never promoted to a draft + # - a draft older than a day that's still identical to head def wipe_draft! return if self.autosave && self.autosave.updated_at > 1.day.ago unless self.draft + return if self.autosave.nil? && self.locked? && self.updated_at > 1.day.ago self.autosave&.destroy self.autosave_id = nil self.unlock! -- cgit v1.3