               :col} ...]}"
   [id :as {{:keys [cards]} :body}]
   (write-check Dashboard id)
-  (doseq [{dashcard-id :id :keys [sizeX sizeY row col]} cards]
-    ;; we lookup the dashcard purely to ensure the card is part of the given dashboard
-    (let [dashcard (sel :one [DashboardCard :id] :id dashcard-id :dashboard_id id)]
-      (when dashcard
-        (upd DashboardCard dashcard-id :sizeX sizeX :sizeY sizeY :row row :col col))))
+  (let [dashcard-ids (set (db/sel :many :field [DashboardCard :id] :dashboard_id id))]
+    (doseq [{dashcard-id :id :keys [sizeX sizeY row col]} cards]
+      ;; ensure the dashcard we are updating is part of the given dashboard
+      (when (contains? dashcard-ids dashcard-id)
+        (db/upd DashboardCard dashcard-id :sizeX sizeX :sizeY sizeY :row row :col col))))
   (events/publish-event :dashboard-reposition-cards {:id id :actor_id *current-user-id* :dashcards cards})
   {:status :ok})
 

  [f]
  {f FilterOptionAllOrMine}
  (-> (case (or f :all)
        :all  (sel :many Dashboard (k/where (or {:creator_id *current-user-id*}
                                                {:public_perms [> common/perms-none]})))
        :mine (sel :many Dashboard :creator_id *current-user-id*))
      (hydrate :creator :can_read :can_write)))

(defendpoint POST "/"

            [korma.core :as k]
            [metabase.events :as events]
            [metabase.api.common :refer :all]
            [metabase.db :as db]
            (metabase.models [hydrate :refer [hydrate]]
                             [card :refer [Card]]
                             [common :as common]
