mirror of
https://github.com/penpot/penpot.git
synced 2025-07-22 01:07:18 +02:00
✨ Simplify trim-file task implementation.
This commit is contained in:
parent
6800adfaa4
commit
fa0e0af5b9
1 changed files with 18 additions and 14 deletions
|
@ -39,23 +39,27 @@
|
||||||
limit 10")
|
limit 10")
|
||||||
|
|
||||||
(defn retrieve-candidates
|
(defn retrieve-candidates
|
||||||
|
"Retrieves a list of ids of files that are candidates to be trimed. A
|
||||||
|
file is considered candidate when some time passes whith no
|
||||||
|
modification."
|
||||||
[conn]
|
[conn]
|
||||||
(let [interval (:file-trimming-max-age cfg/config)]
|
(let [interval (:file-trimming-max-age cfg/config)]
|
||||||
(->> (db/exec! conn [sql:retrieve-files-to-trim interval])
|
(->> (db/exec! conn [sql:retrieve-files-to-trim interval])
|
||||||
(map :id))))
|
(map :id))))
|
||||||
|
|
||||||
(defn collect-used-media
|
|
||||||
[pages]
|
(def collect-media-xf
|
||||||
(let [xf (comp (filter #(= :image (:type %)))
|
(comp (map :data)
|
||||||
(map :metadata)
|
|
||||||
(map :id))]
|
|
||||||
(reduce conj #{} (->> pages
|
|
||||||
(map :data)
|
|
||||||
(map :objects)
|
(map :objects)
|
||||||
(mapcat vals)
|
(mapcat vals)
|
||||||
(filter #(= :image (:type %)))
|
(filter #(= :image (:type %)))
|
||||||
(map :metadata)
|
(map :metadata)
|
||||||
(map :id)))))
|
(map :id)))
|
||||||
|
|
||||||
|
|
||||||
|
(defn collect-used-media
|
||||||
|
[pages]
|
||||||
|
(into #{} collect-media-xf pages))
|
||||||
|
|
||||||
(defn process-file
|
(defn process-file
|
||||||
[file-id]
|
[file-id]
|
||||||
|
@ -64,17 +68,17 @@
|
||||||
(let [mobjs (db/query conn :media-object {:file-id file-id})
|
(let [mobjs (db/query conn :media-object {:file-id file-id})
|
||||||
pages (->> (db/query conn :page {:file-id file-id})
|
pages (->> (db/query conn :page {:file-id file-id})
|
||||||
(map decode-row))
|
(map decode-row))
|
||||||
used (collect-used-media pages)
|
used (into #{} collect-media-xf pages)
|
||||||
unused (into #{} (comp (map :id)
|
unused (into #{} (comp (map :id) (remove #(contains? used %))) mobjs)]
|
||||||
(remove #(contains? used %))) mobjs)]
|
|
||||||
(log/debugf "Collected media ids: '%s'." (pr-str used))
|
(log/debugf "Collected media ids: '%s'." (pr-str used))
|
||||||
(log/debugf "Unused media ids: '%s'." (pr-str unused))
|
(log/debugf "Unused media ids: '%s'." (pr-str unused))
|
||||||
|
|
||||||
(db/update! conn :file
|
(db/update! conn :file
|
||||||
{:has-media-trimmed true}
|
{:has-media-trimmed true}
|
||||||
{:id file-id})
|
{:id file-id})
|
||||||
|
|
||||||
(doseq [id unused]
|
(doseq [id unused]
|
||||||
|
;; TODO: add task batching
|
||||||
(tasks/submit! conn {:name "delete-object"
|
(tasks/submit! conn {:name "delete-object"
|
||||||
;; :delay cfg/default-deletion-delay
|
;; :delay cfg/default-deletion-delay
|
||||||
:delay 10000
|
:delay 10000
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue