diff --git a/backend/src/app/tasks/file_gc.clj b/backend/src/app/tasks/file_gc.clj index 1cfc71b9a3..d168bda095 100644 --- a/backend/src/app/tasks/file_gc.clj +++ b/backend/src/app/tasks/file_gc.clj @@ -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)] diff --git a/backend/test/backend_tests/rpc_file_test.clj b/backend/test/backend_tests/rpc_file_test.clj index 376f412b1b..3c6a8a46ea 100644 --- a/backend/test/backend_tests/rpc_file_test.clj +++ b/backend/test/backend_tests/rpc_file_test.clj @@ -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 diff --git a/common/src/app/common/flags.cljc b/common/src/app/common/flags.cljc index e76dc92f84..08bae79bd0 100644 --- a/common/src/app/common/flags.cljc +++ b/common/src/app/common/flags.cljc @@ -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.