From 1c62281cbe03b653ea43abc70bfac490f1f59f16 Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Thu, 21 Nov 2024 21:16:19 +0530 Subject: [PATCH 1/2] Changes to reduce API calls for Developer & Company Apps listing --- src/Controller/PaginationHelperTrait.php | 33 +++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Controller/PaginationHelperTrait.php b/src/Controller/PaginationHelperTrait.php index e373f6ce..d018ca82 100644 --- a/src/Controller/PaginationHelperTrait.php +++ b/src/Controller/PaginationHelperTrait.php @@ -326,22 +326,31 @@ 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). + if (count($ids) > 100) { + $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; } From 4f75b5ddc7fa1697448098c6b7a5ab9fd5c91a29 Mon Sep 17 00:00:00 2001 From: Kedar Khaire Date: Fri, 29 Nov 2024 21:48:32 +0530 Subject: [PATCH 2/2] changes for limit and added comment for changes --- src/Controller/PaginationHelperTrait.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Controller/PaginationHelperTrait.php b/src/Controller/PaginationHelperTrait.php index d018ca82..c56fe1f5 100644 --- a/src/Controller/PaginationHelperTrait.php +++ b/src/Controller/PaginationHelperTrait.php @@ -326,7 +326,19 @@ private function listEntityIdsWithCps(?PagerInterface $pager = null, array $quer if (empty($ids)) { return []; } - if (count($ids) > 100) { + // 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);