   ([db user]
    (get-share db user (util/get-all-resource-types db)))
   ([db user resource-types]
-   (pc/map-from-keys (fn get-share-3p-helper [type] (get-share-by-type db type user))
-                     resource-types))
+   (let [type->default (get-share-by-types db default-user resource-types {})]
+     (get-share db user resource-types type->default)))
   ([db user resource-types type->default]
-   (pc/map-from-keys (fn get-share-4p-helper [type] (get-share-by-type db type user (type->default type)))
-                     resource-types)))
+   (get-share-by-types db user resource-types type->default)))
 
 (timers/deftimer [cook-mesos share get-shares-duration])
 

  ([db users resource-types]
   (timers/time!
     get-shares-duration
     (let [type->default (-> (fn [type] (get-share-by-type db type default-user Double/MAX_VALUE))
                             (pc/map-from-keys resource-types))]
       (-> (fn [user] (get-share db user resource-types type->default))
           (pc/map-from-keys users))))))


                   [[:db.fn/retractEntity resource]])
      (log/warn "Resource" type "for user" user "does not exist, could not retract"))))

(defn get-share-by-types
  "Query a user's pre-defined share by types (e.g. [:cpus, :mem, :gpus]).
   Returns a map from resource type to amount (double value).

   If a user's pre-defined share is NOT defined for a specific resource type, return either:
   1. the explicitly provided default value in type->share, or
   2. the share for the \"default\" user. If there is NO \"default\"
      value for a specific type, return Double.MAX_VALUE."
  [db user types type->share]
  (let [query '[:find ?t ?a
                :in $ ?u [?t ...]
                :where
                [?e :share/user ?u]
                [?e :share/resource ?r]
                [?r :resource/type ?t]
                [?r :resource/amount ?a]]
        datomic-resource-types (map resource-type->datomic-resource-type types)
        default-type->share (pc/map-from-keys
                              (fn [type] (get type->share type Double/MAX_VALUE))
                              types)]
    (->> (q query db user datomic-resource-types)
         (into {})
         (pc/map-keys datomic-resource-type->resource-type)
         (merge default-type->share))))

(defn get-share
  "Query a user's pre-defined share.
