✨ Add a flag that makes file-gc skip its media clean-up (#13220)

The new backend flag `file-change-retention`, off by default, makes
file-gc skip its media clean-up (deleted components, unused media
objects, and thumbnails). That clean-up roots only in the head and the
snapshots, so it would remove media that a kept revision row still
names. The file and fragment clean-up still run: revision rows name
neither.

penpot#13187 keeps revision rows under the same flag. Set the flag only
where both are deployed. An instance that rolls back to this release
with the flag still set keeps the media its retained history needs.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Álvaro Tejero-Cantero 2026-11-20 13:15:35 +01:00 committed by GitHub
parent 212ee6ef48
commit 932544996f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 2 deletions

View File

@ -272,9 +272,14 @@
(feat.fdata/with-pointers cfg file-id
(let [liveness (collect-snapshot-liveness cfg file-id)
original (feat.fdata/original-pointers (:data file))
file (bfl/clean-file file)
;; With retention on, kept revision rows can name media and
;; components that neither the head nor the snapshots name,
;; and the media cleaners do not read those rows.
file (if (contains? cf/flags :file-change-retention)
file
(clean-media! cfg liveness file))
file (->> file
(bfl/clean-file)
(clean-media! cfg liveness)
(feat.fdata/reattach-unchanged original)
(clean-fragments! cfg (:pointers liveness)))
file (assoc file :has-media-trimmed true)]

View File

@ -3537,6 +3537,22 @@
(t/is (true? (th/run-task! :file-gc {:file-id (:id file)})))
(t/is (empty? (:call-args-list @audit-mock)))))))
(t/deftest file-gc-keeps-unused-media-with-the-retention-flag
;; A kept revision row can name a media object that the head no longer
;; names, and file-gc does not read revision rows, so the flag turns its
;; media clean-up off.
(let [[_ file-1] (unused-media-fixture 1)
[_ file-2] (unused-media-fixture 2)
media-row (fn [file] (th/db-get :file-media-object {:file-id (:id file)}
{::db/remove-deleted false}))]
(t/is (true? (th/run-task! :file-gc {:file-id (:id file-1)})))
(with-redefs [cf/flags (conj cf/flags :file-change-retention)]
(t/is (true? (th/run-task! :file-gc {:file-id (:id file-2)}))))
(t/is (ct/inst? (:deleted-at (media-row file-1))))
(t/is (nil? (:deleted-at (media-row file-2))))
(t/is (true? (:has-media-trimmed (th/db-get :file {:id (:id file-2)}))))))
(t/deftest update-file-audit-event-carries-the-file-change-id
;; The event says that a file was saved, but not what changed: the
;; change row (xlog) is the only place with that, so its id travels

View File

@ -90,6 +90,11 @@
;; on the database (server-error-report) and notified to mattermost
;; (only when the webhook url is also configured).
:error-reporting
;; Disabled by default. When enabled, file-gc skips its media clean-up,
;; which does not read revision rows, and the revision writer keeps
;; revision rows with no expiry (penpot#13187). Enable it only where
;; both are deployed.
:file-change-retention
;; Activates the schema validation during update file.
:file-schema-validation
;; Reports the schema validation errors internally.