mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 00:40:30 -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)
|
(let [min-age (db/interval min-age)
|
||||||
rows (db/exec! conn [sql:retrieve-deleted-objects-chunk min-age cursor])]
|
rows (db/exec! conn [sql:retrieve-deleted-objects-chunk min-age cursor])]
|
||||||
[(some-> rows peek :created-at)
|
[(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]
|
(retrieve-deleted-objects [conn]
|
||||||
(->> (d/iteration (fn [cursor]
|
(->> (d/iteration (fn [cursor]
|
||||||
|
@ -383,7 +383,7 @@
|
||||||
(mapv #(d/update-when % :metadata db/decode-transit-pgobject)))]
|
(mapv #(d/update-when % :metadata db/decode-transit-pgobject)))]
|
||||||
(when (seq rows)
|
(when (seq rows)
|
||||||
[(-> rows peek :created-at)
|
[(-> rows peek :created-at)
|
||||||
(d/group-by' get-bucket :id rows)])))
|
(d/group-by get-bucket :id #{} rows)])))
|
||||||
|
|
||||||
(retrieve-touched [conn]
|
(retrieve-touched [conn]
|
||||||
(->> (d/iteration (fn [cursor]
|
(->> (d/iteration (fn [cursor]
|
||||||
|
|
|
@ -597,19 +597,10 @@
|
||||||
|
|
||||||
|
|
||||||
(defn group-by
|
(defn group-by
|
||||||
([kf coll] (group-by kf identity coll))
|
([kf coll] (group-by kf identity [] coll))
|
||||||
([kf vf coll]
|
([kf vf coll] (group-by kf vf [] coll))
|
||||||
(let [conj (fnil conj [])]
|
([kf vf iv coll]
|
||||||
(reduce (fn [result item]
|
(let [conj (fnil conj iv)]
|
||||||
(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 #{})]
|
|
||||||
(reduce (fn [result item]
|
(reduce (fn [result item]
|
||||||
(update result (kf item) conj (vf item)))
|
(update result (kf item) conj (vf item)))
|
||||||
{}
|
{}
|
||||||
|
|
Loading…
Reference in a new issue