Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to reduce API calls for Developer & Company Apps listing #396

Open
wants to merge 2 commits into
base: 3.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions src/Controller/PaginationHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,43 @@ private function listEntityIdsWithCps(?PagerInterface $pager = null, array $quer
if (empty($ids)) {
return [];
}
$lastId = end($ids);
do {
$tmp = $this->getResultsInRange($this->createPager(0, $lastId), $query_params, $expandCompatibility);
// Remove the first item from the list because it is the same
// as the current last item of $ids.
// Apigee Edge response always starts with the requested entity
// id (startKey).
// The default pagination limit (aka. "count") on CPS supported
// listing endpoints varies. When this script was written it was
// 1000 on two endpoints and 100 on two app related endpoints,
// namely List Developer Apps and List Company Apps. A
// developer/company should not have 100 apps, this is
// the reason why this limit is smaller. Therefore we choose to
// use 1000 as max limit to improve performance of page.
// Developers & Companies with more than 100 Apps will face
// performance issue.
// https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/apiproducts-0
// https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers
// https://apidocs.apigee.com/management/apis/get/organizations/%7Borg_name%7D/developers/%7Bdeveloper_email_or_id%7D/apps
if (count($ids) > 1000) {
$lastId = end($ids);
do {
$tmp = $this->getResultsInRange($this->createPager(0, $lastId), $query_params, $expandCompatibility);
// Remove the first item from the list because it is the same
// as the current last item of $ids.
// Apigee Edge response always starts with the requested entity
// id (startKey).
array_shift($tmp);
if (count($tmp) > 0) {
$ids = array_merge($ids, $tmp);
$lastId = end($tmp);
} else {
$lastId = false;
}
} while ($lastId);
} else {
// Condition added to load the expanded details for each app in a single call.
$query_params = ['expand' => 'true'];
$tmp = $this->getResultsInRange($this->createPager(), $query_params, $expandCompatibility);
array_shift($tmp);

if (count($tmp) > 0) {
$ids = array_merge($ids, $tmp);
$lastId = end($tmp);
} else {
$lastId = false;
}
} while ($lastId);
}

return $ids;
}
Expand Down
Loading