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

Iterator final touches #521

Merged
merged 10 commits into from
Nov 16, 2023
Merged

Iterator final touches #521

merged 10 commits into from
Nov 16, 2023

Conversation

ecoologic
Copy link
Collaborator

@ecoologic ecoologic commented Nov 14, 2023

  • Fix issue with Iterator API call frequency
  • Expose the API call response for debugging and custom implementations
  • Documentation
  • Refactoring

Get a page only if no item in memory
@ecoologic ecoologic force-pushed the RED-1955-iterator-correct-fetches branch from 32382c9 to 2c759f2 Compare November 14, 2023 04:09
private function getPageIfNeeded()
{
if (!$this->strategy->shouldGetPage($this->position)) {
if (isset($this->page[$this->position]) || !$this->strategy->shouldGetPage($this->position)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before, loop cycle was making an HTTP call till all records were fetched, now it waits until it's done processing the whole page.

@ecoologic ecoologic force-pushed the RED-1955-iterator-correct-fetches branch from 2c759f2 to 25187e2 Compare November 14, 2023 04:26
return;
}

$getPageFn = function () {
return $this->clientList->{$this->method}($this->strategy->params());
};

$this->page = array_merge($this->page, $this->strategy->page($getPageFn));
$this->items = array_merge($this->items, $this->strategy->page($getPageFn));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ecoologic ecoologic requested review from a team and 7ail November 14, 2023 04:35
@ecoologic ecoologic marked this pull request as ready for review November 14, 2023 04:36
@ecoologic ecoologic force-pushed the RED-1955-iterator-correct-fetches branch from 1e08103 to 339610d Compare November 14, 2023 05:14

$this->assertEquals($mockException, $previousException, $message);
$this->assertEquals([], $subject->getErrorDetails());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

admittedly not a great test, but better than deleting the file.

@ecoologic ecoologic force-pushed the RED-1955-iterator-correct-fetches branch from d83f028 to ca1f2c9 Compare November 15, 2023 01:29
@ecoologic ecoologic force-pushed the RED-1955-iterator-correct-fetches branch 3 times, most recently from d32af7e to cae5e86 Compare November 15, 2023 22:44
@ecoologic ecoologic force-pushed the RED-1955-iterator-correct-fetches branch from cae5e86 to 2ce8083 Compare November 15, 2023 23:56
$this->latestResponse = $getPageFn();
if (!isset($this->latestResponse->meta->has_more)) {
throw new PaginationError(
"Response not conforming to the CBP format, if you think your request is correct, please open an issue at https://github.com/zendesk/zendesk_api_client_php/issues"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you come across a case like this? can you try CBP requests on resources that do not implement them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found any. But the iterator can be used in a customized way by the final users, so it can either be a problem with an endpoint that we missed (php also defines chat, talk, HC, voice). This is a friendly error so that the final user won't have to debug our code.

@@ -1,5 +1,7 @@
# OBP to CBP Upgrade guide

TODO version requirement, how to bump.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing this to do is meant to be there and will be filled out later?

Copy link
Collaborator Author

@ecoologic ecoologic Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thanks, this is the upcoming work. To be addressed in a separate PR.

@ecoologic ecoologic merged commit 95b9632 into master Nov 16, 2023
2 checks passed
@ecoologic ecoologic deleted the RED-1955-iterator-correct-fetches branch November 16, 2023 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants