mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 08:20:45 -05:00
✨ Simplify d/group-by impl
This commit is contained in:
parent
c876534c85
commit
1943877b21
2 changed files with 6 additions and 15 deletions
|
@ -274,7 +274,7 @@
|
|||
(let [min-age (db/interval min-age)
|
||||
rows (db/exec! conn [sql:retrieve-deleted-objects-chunk min-age cursor])]
|
||||
[(some-> rows peek :created-at)
|
||||
(some->> (seq rows) (d/group-by' #(-> % :backend keyword) :id) seq)]))
|
||||
(some->> (seq rows) (d/group-by #(-> % :backend keyword) :id #{}) seq)]))
|
||||
|
||||
(retrieve-deleted-objects [conn]
|
||||
(->> (d/iteration (fn [cursor]
|
||||
|
@ -383,7 +383,7 @@
|
|||
(mapv #(d/update-when % :metadata db/decode-transit-pgobject)))]
|
||||
(when (seq rows)
|
||||
[(-> rows peek :created-at)
|
||||
(d/group-by' get-bucket :id rows)])))
|
||||
(d/group-by get-bucket :id #{} rows)])))
|
||||
|
||||
(retrieve-touched [conn]
|
||||
(->> (d/iteration (fn [cursor]
|
||||
|
|
|
@ -597,19 +597,10 @@
|
|||
|
||||
|
||||
(defn group-by
|
||||
([kf coll] (group-by kf identity coll))
|
||||
([kf vf coll]
|
||||
(let [conj (fnil conj [])]
|
||||
(reduce (fn [result item]
|
||||
(update result (kf item) conj (vf item)))
|
||||
{}
|
||||
coll))))
|
||||
|
||||
(defn group-by'
|
||||
"A variant of group-by that uses a set for collecting results."
|
||||
([kf coll] (group-by kf identity coll))
|
||||
([kf vf coll]
|
||||
(let [conj (fnil conj #{})]
|
||||
([kf coll] (group-by kf identity [] coll))
|
||||
([kf vf coll] (group-by kf vf [] coll))
|
||||
([kf vf iv coll]
|
||||
(let [conj (fnil conj iv)]
|
||||
(reduce (fn [result item]
|
||||
(update result (kf item) conj (vf item)))
|
||||
{}
|
||||
|
|
Loading…
Reference in a new issue