Add file cleaner to file-gc process

This commit is contained in:
Andrey Antukh 2025-04-23 10:06:53 +02:00
parent fef19a3c80
commit 694a2084e2
2 changed files with 15 additions and 8 deletions

View file

@ -90,13 +90,18 @@
(fix-root-shape) (fix-root-shape)
(fix-legacy-flex-dir))) (fix-legacy-flex-dir)))
(defn- fix-container
[container]
(-> container
;; Remove possible `nil` keys on objects
(d/update-when :objects dissoc nil)
(d/update-when :objects d/update-vals clean-shape-post-decode)))
(defn clean-file (defn clean-file
[file & {:as _opts}] [file & {:as _opts}]
(let [update-container (update file :data
(fn [container] (fn [data]
(d/update-when container :objects d/update-vals clean-shape-post-decode))] (-> data
(update file :data (d/update-when :pages-index d/update-vals fix-container)
(fn [data] (d/update-when :components d/update-vals fix-container)
(-> data (d/without-nils)))))
(update :pages-index d/update-vals update-container)
(update :components d/update-vals update-container))))))

View file

@ -10,6 +10,7 @@
file is eligible to be garbage collected after some period of file is eligible to be garbage collected after some period of
inactivity (the default threshold is 72h)." inactivity (the default threshold is 72h)."
(:require (:require
[app.binfile.cleaner :as bfl]
[app.binfile.common :as bfc] [app.binfile.common :as bfc]
[app.common.files.helpers :as cfh] [app.common.files.helpers :as cfh]
[app.common.files.validate :as cfv] [app.common.files.validate :as cfv]
@ -258,6 +259,7 @@
(if-let [file (get-file cfg file-id)] (if-let [file (get-file cfg file-id)]
(let [file (->> file (let [file (->> file
(bfc/decode-file cfg) (bfc/decode-file cfg)
(bfl/clean-file)
(clean-media! cfg) (clean-media! cfg)
(clean-fragments! cfg)) (clean-fragments! cfg))
file (assoc file :has-media-trimmed true)] file (assoc file :has-media-trimmed true)]