FR: Disable saving a draft or entry until autosave completes #15013
-
I suggest disabling any form submisson on an entry until autosave completes its request. If a site has some event listeners taking longer or an autosave is slow (ex: php child queue delay) and the user saves while it's running, there can be unintended consequences. We've seen duplicate supertable and matrix blocks when this condition occurs. I've provided more information on this supertable issue. There could be some fixes and optimizations needed on the plugin side, but it seems best to plan for the Craft editor being able to submit a save or create on an entry or draft while an autosave is still processing for any reason. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Craft ensures the same entry isn’t saved multiple times at the same time, via a mutex lock. If that’s not working for you, it might be because your We improved the default The mutex lock won’t cover queue jobs though. Queue jobs are run asynchronously, usually after a delay. So if you’re doing some additional work on an entry via a queue job, preventing entry saves until after the autosave is complete (as you’re suggesting) wouldn’t help you there. Instead you should probably wrap your queue job logic in a mutex lock, that ensures it’s not competing with another entry save request. // acquire a mutex lock for the entry
$lockKey = "element:$entry->id";
if (!Craft::$app->mutex->acquire($lockKey, 15)) {
throw new \Exception('Could not acquire a lock to save the entry.');
}
// perform the actions...
// release the mutex lock
Craft::$app->mutex->release($lockKey); |
Beta Was this translation helpful? Give feedback.
Craft ensures the same entry isn’t saved multiple times at the same time, via a mutex lock.
If that’s not working for you, it might be because your
mutex
component isn’t configured properly for the environment.We improved the default
mutex
driver in Craft 4.6, which is now safe to use regardless of your hosting environment, so the easiest way to fix would be to ensure you’re running Craft 4.6+, and then go toconfig/app.php
and delete your custommutex
config (if you have one).The mutex lock won’t cover queue jobs though. Queue jobs are run asynchronously, usually after a delay. So if you’re doing some additional work on an entry via a queue job, preventing entry saves until after the a…