about summary refs log tree commit diff
path: root/users/grfn/bbbg/src/bbbg/db/attendee_check.clj
diff options
context:
space:
mode:
Diffstat (limited to 'users/grfn/bbbg/src/bbbg/db/attendee_check.clj')
-rw-r--r--users/grfn/bbbg/src/bbbg/db/attendee_check.clj47
1 files changed, 25 insertions, 22 deletions
diff --git a/users/grfn/bbbg/src/bbbg/db/attendee_check.clj b/users/grfn/bbbg/src/bbbg/db/attendee_check.clj
index 66090b16c603..33ed98d4ffbd 100644
--- a/users/grfn/bbbg/src/bbbg/db/attendee_check.clj
+++ b/users/grfn/bbbg/src/bbbg/db/attendee_check.clj
@@ -8,28 +8,31 @@
 
 (defn attendees-with-last-checks
   [db attendees]
-  (let [ids (map ::attendee/id attendees)
-        checks
-        (db/list db {:select [:attendee-check.*]
-                     :from [:attendee-check]
-                     :join [[{:select [:%max.attendee-check.checked-at
-                                       :attendee-check.attendee-id]
-                              :from [:attendee-check]
-                              :group-by [:attendee-check.attendee-id]
-                              :where [:in :attendee-check.attendee-id ids]}
-                             :last-check]
-                            [:=
-                             :attendee-check.attendee-id
-                             :last-check.attendee-id]]})
-        users (u/key-by
-               ::user/id
-               (db/list db {:select [:public.user.*]
-                            :from [:public.user]
-                            :where [:in :id (map ::user/id checks)]}))
-        checks (map #(assoc % :user (users (::user/id %))) checks)
-        attendee-id->check (u/key-by ::attendee/id checks)]
-    (map #(assoc % :last-check (attendee-id->check (::attendee/id %)))
-         attendees)))
+  (when (seq attendees)
+    (let [ids (map ::attendee/id attendees)
+          checks
+          (db/list db {:select [:attendee-check.*]
+                       :from [:attendee-check]
+                       :join [[{:select [:%max.attendee-check.checked-at
+                                         :attendee-check.attendee-id]
+                                :from [:attendee-check]
+                                :group-by [:attendee-check.attendee-id]
+                                :where [:in :attendee-check.attendee-id ids]}
+                               :last-check]
+                              [:=
+                               :attendee-check.attendee-id
+                               :last-check.attendee-id]]})
+          users (if (seq checks)
+                  (u/key-by
+                   ::user/id
+                   (db/list db {:select [:public.user.*]
+                                :from [:public.user]
+                                :where [:in :id (map ::user/id checks)]}))
+                  {})
+          checks (map #(assoc % :user (users (::user/id %))) checks)
+          attendee-id->check (u/key-by ::attendee/id checks)]
+      (map #(assoc % :last-check (attendee-id->check (::attendee/id %)))
+           attendees))))
 
 (comment
   (def db (:db bbbg.core/system))