Skip to content

Conversation

@toph-allen
Copy link
Collaborator

Intent

Add auto-pagination to search_content().

Fixes #447

Approach

  • Moved the raw API call to an inner function, which is called with page_offset().

Checklist

  • Does this change update NEWS.md (referencing the connected issue if necessary)?
  • Does this change need documentation? Have you run devtools::document()?

@toph-allen toph-allen requested a review from jonkeane October 2, 2025 23:07
Comment on lines -1590 to -1591
page_number = 1,
page_size = 500,
Copy link
Collaborator Author

@toph-allen toph-allen Oct 2, 2025

Choose a reason for hiding this comment

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

I figured we don't need to expose these to users, since pagination is kind of an implementation detail here. But retaining them and passing them down might make it easier to test performance under different values.

Copy link
Contributor

Choose a reason for hiding this comment

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

But retaining them and passing them down might make it easier to test performance under different values

Yeah, that's true. A few thoughts: (1) one should be able to pass these down in ... even if they are not included in the signature explicitly. (2) what do our other functions do? If they expose these explicitly so that it's obvious there are nobs to tune here, I'm fine including them. But also fine to not (so long as someone can pass them in ...)

Copy link
Collaborator Author

@toph-allen toph-allen Oct 3, 2025

Choose a reason for hiding this comment

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

Our other functions don't expose them to users, and ultimately that's the right choice. I will add a test to ensure they get passed down.

I'll note that passing in page_number will just be the starting page of pagination — pagination will still happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, sounds good.

I'll note that passing in page_number will just be the starting page of pagination — pagination will still happen.

I'm not sure if this is the right behavior (but we shouldn't fix that here since that's more about the implementation of page_offset). Could you (1) write an issue for this and (2) it would be good to write this down, in a comment at least, but maybe even in the body of the documentation (since we're not explicitly documenting page_number the obvious place is gone, but that's ok even if it's just in the narrative section of the docs, just so someone confused about this and looking would see it).

Copy link
Collaborator Author

@toph-allen toph-allen Oct 3, 2025

Choose a reason for hiding this comment

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

I'm not sure if this is the right behavior (but we shouldn't fix that here since that's more about the implementation of page_offset). Could you (1) write an issue for this and (2) it would be good to write this down, in a comment at least, but maybe even in the body of the documentation (since we're not explicitly documenting page_number the obvious place is gone, but that's ok even if it's just in the narrative section of the docs, just so someone confused about this and looking would see it).

Yeah, this non-intuitiveness was kinda in there in my reasoning for not wanting to include it as an explicit parameter. I'll do both.

[edit] #450

Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree on passing the parameters with .... My opinion is that parameters that go through ... should get passed to exported functions with their own documentation. If the only place they're documented is through the ... documentation for this function, to me that just obfuscates them unnecessarily. If we're going to support people providing pagination-related arguments then let's give them informative names that can pop up in tab-completion, etc.

This is just an opinion and doesn't need to block the PR if others feel strongly about the current approach, however.

toph-allen and others added 2 commits October 3, 2025 11:49
@toph-allen toph-allen requested a review from jonkeane October 3, 2025 15:54
Copy link
Contributor

@jonkeane jonkeane left a comment

Choose a reason for hiding this comment

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

This is great, thanks for something so targeted. I have one suggested improvement, but if you decide not to do that here, that shouldn't hold up the merge.

Comment on lines 499 to 510
test_that("content search passes all parameters through correctly", {
without_internet(
expect_GET(
search_content(
client,
q = "bream",
include = "owner",
page_number = 2,
page_size = 5
page_size = 20,
include = "owner"
),
"https://connect.example/__api__/v1/search/content?q=bream&page_number=2&page_size=5&include=owner"
"https://connect.example/__api__/v1/search/content?q=bream&page_number=2&page_size=20&include=owner"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is just an edit, but this is a great example of the power of httptest: we can assert our handling of the responses where that's important, but here we just need to know it's constructing the URLs correctly to know that we're doing the right thing. 💯

Comment on lines -1590 to -1591
page_number = 1,
page_size = 500,
Copy link
Contributor

Choose a reason for hiding this comment

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

I disagree on passing the parameters with .... My opinion is that parameters that go through ... should get passed to exported functions with their own documentation. If the only place they're documented is through the ... documentation for this function, to me that just obfuscates them unnecessarily. If we're going to support people providing pagination-related arguments then let's give them informative names that can pop up in tab-completion, etc.

This is just an opinion and doesn't need to block the PR if others feel strongly about the current approach, however.

@toph-allen
Copy link
Collaborator Author

toph-allen commented Oct 3, 2025

I disagree on passing the parameters with .... My opinion is that parameters that go through ... should get passed to exported functions with their own documentation. If the only place they're documented is through the ... documentation for this function, to me that just obfuscates them unnecessarily. If we're going to support people providing pagination-related arguments then let's give them informative names that can pop up in tab-completion, etc.

@karawoo Good point. It does have a bad feel to it.

The other functions that wrap paginated endpoints don't provide pagination controls, and my original intent for this func was to do the same. Added them back in because we may want to use them to test performance of different page_sizes.

Your point makes me feel that including them in ... is probably a bad compromise between my original intent and current functionality. But the behavior of page_number is funky and I have #450 to fix that — I'd like to postpone making the params explicit until that issue.

[edit] I've captured in #450 that the params should be explicit.

@toph-allen toph-allen merged commit dc55d83 into main Oct 3, 2025
21 checks passed
@toph-allen toph-allen deleted the toph/paginate-search-content branch October 3, 2025 17:34
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.

feat: add auto-pagination to search_content() function

4 participants