0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 00:10:11 -05:00

♻️ Refactor thumbnails queue to priority queue

This commit is contained in:
Aitor 2023-11-23 16:01:23 +01:00 committed by Andrey Antukh
parent 49203f53aa
commit 1de2af744f

View file

@ -85,7 +85,15 @@
(let [items (unchecked-get queue "items")]
(.shift items)))
(defn enqueue
(defn enqueue-first
[queue item]
(assert (instance? Queue queue))
(let [items (unchecked-get queue "items")]
(.unshift items item)
(when-not (has-requested-process? queue)
(request-process queue (next-process-time queue)))))
(defn enqueue-last
[queue item]
(assert (instance? Queue queue))
(let [items (unchecked-get queue "items")]
@ -97,5 +105,13 @@
[queue item f]
(assert (instance? Queue queue))
(let [items (unchecked-get queue "items")]
(when-not (.findLast ^js items f)
(enqueue queue item))))
;; If tag is "frame", then they are added to the front of the queue
;; so that they are processed first, anything else is added to the
;; end of the queue.
(if (= (unchecked-get item "tag") "frame")
(when-not (.find ^js items f)
(enqueue-first queue item))
(when-not (.findLast ^js items f)
(enqueue-last queue item)))
(when-not (has-requested-process? queue)
(request-process queue (next-process-time queue)))))