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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] java: pagination #3632

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

[WIP] java: pagination #3632

wants to merge 8 commits into from

Conversation

dcb6
Copy link
Contributor

@dcb6 dcb6 commented May 15, 2024

No description provided.

@dcb6 dcb6 force-pushed the burke/fer-1769-formance-pagination branch from a2fb89e to 3806580 Compare June 6, 2024 18:38
.startingAfter(startingAfter)
.build();
return new SyncPagingIterable<>(startingAfter.isPresent(), parsedResponse.getData(),
() -> listWithCursorPagination(nextRequest, requestOptions));
}
Copy link
Contributor Author

@dcb6 dcb6 Jun 6, 2024

Choose a reason for hiding this comment

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

Example block for offset pagination (from hume, includes handling a response that's an Optional<List< ... >>)

                FilePage parsedResponse = ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FilePage.class);
                Integer newPageNumber = request.getPageNumber().map(page -> page + 1).orElse(1);
                FilesListFilesRequest nextRequest = FilesListFilesRequest.builder()
                        .from(request)
                        .pageNumber(newPageNumber)
                        .build();
                return new SyncPagingIterable<>(
                        true, parsedResponse.getContent(), () -> listFiles(nextRequest, requestOptions));

super(hasNext, items, getNext);
}

public SyncPagingIterable(boolean hasNext, Optional<List<T>> items, Supplier<? extends SyncPage<T>> getNext) {
Copy link
Contributor Author

@dcb6 dcb6 Jun 6, 2024

Choose a reason for hiding this comment

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

made this extra constructor to handle an Optional items for 2 reasons:

  1. this basically delegates some extra logic to this class instead of the client method. imo feels most important to keep client methods clean over core classes; i'd imagine people spend more time looking at clients
  2. a bit easier to implement this way!

public SyncPagingIterable(boolean hasNext, Optional<List<T>> items, Supplier<? extends SyncPage<T>> getNext) {
super(hasNext, items.orElse(new ArrayList<>()), getNext);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In addition to the itererator, should we have a way to get all of the values in a list or stream easily? like a toList()?

my vote: make a ticket and consider adding this in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant