Skip to content

Commit

Permalink
CMR-4312 adds chunking to query, originally only had batches of resul…
Browse files Browse the repository at this point in the history
…ts (#165)

* CMR-4312 adds chunking to query, originally only had batches of results

* CMR-4312 chris's pr comments
  • Loading branch information
daniel-zamora authored Jun 29, 2017
1 parent aa9fb35 commit b0031d6
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions access-control-app/src/cmr/access_control/services/acl_util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,19 @@
identity-type-condition)]
(get-acls-by-condition context condition)))

(defn get-collections-chunked
"Searches for collections in chunks."
[context values field provider-id]
(let [chunk-size (config/sync-entry-titles-concept-ids-collection-batch-size)
chunked-values (partition chunk-size chunk-size nil values)]
(mapcat #(mdb1/find-concepts context
{:exclude-metadata true
:latest true
field %
:provider-id provider-id}
:collection)
chunked-values)))

(defn sync-entry-titles-concept-ids
"If the given ACL is a catalog item acl with a collection identifier that includes concept-ids or
entry-titles, return the ACL such that both are unioned with each other."
Expand All @@ -114,19 +127,9 @@
concept-ids (:concept-ids collection-identifier)
provider-id (get-in acl [:catalog-item-identity :provider-id])
colls-from-entry-titles (when (seq entry-titles)
(for [batch (mdb1/find-in-batches context
:collection
(config/sync-entry-titles-concept-ids-collection-batch-size)
{:provider-id provider-id :entry-title entry-titles})
collection batch]
collection))
(get-collections-chunked context entry-titles :entry-title provider-id))
colls-from-concept-ids (when (seq concept-ids)
(for [batch (mdb1/find-in-batches context
:collection
(config/sync-entry-titles-concept-ids-collection-batch-size)
{:provider-id provider-id :concept-id concept-ids})
collection batch]
collection))
(get-collections-chunked context concept-ids :concept-id provider-id))
collections (distinct (concat colls-from-entry-titles colls-from-concept-ids))
concept-ids (map :concept-id collections)
entry-titles (map #(get-in % [:extra-fields :entry-title]) collections)
Expand Down

0 comments on commit b0031d6

Please sign in to comment.