Fix: move document files once per request, after its writes commit

A tag PATCH moved files from inside the tags.set() transaction while holding the document row lock. A concurrent save holding media.lock and waiting on that row deadlocked with it, and every later save on the instance queued behind media.lock until the webserver restarted.

FileMoveMiddleware opens a file move scope around every request, in sync or async mode, so each changed document is moved once after the view returns and never while a transaction holds row locks.
This commit is contained in:
stumpylog authored and Trenton H committed 2026-11-29 13:43:02 -08:00
1 parent 7a176da751
commit becfdbaaea
5 files changed
+333

No files matched your search

+1
View File
@@ -188,6 +188,7 @@ if DEBUG:
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"paperless.middleware.FileMoveMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"corsheaders.middleware.CorsMiddleware",