From 1943877b216d66c6a76e77b74329f44e412e221a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 22 Mar 2022 17:23:41 +0100 Subject: [PATCH] :sparkles: Simplify d/group-by impl --- backend/src/app/storage.clj | 4 ++-- common/src/app/common/data.cljc | 17 ++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/backend/src/app/storage.clj b/backend/src/app/storage.clj index 218835149..10e289b7e 100644 --- a/backend/src/app/storage.clj +++ b/backend/src/app/storage.clj @@ -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] diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index eb74bd3a4..08c952d93 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -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))) {}