Skip to content

Add multi-column pagination support#522

Closed
smklein wants to merge 5 commits into
mainfrom
pag_multicolumn
Closed

Add multi-column pagination support#522
smklein wants to merge 5 commits into
mainfrom
pag_multicolumn

Conversation

@smklein

@smklein smklein commented Dec 16, 2021

Copy link
Copy Markdown
Collaborator

See #512 for context / desired usage.

This extends the paginated function to a two-column variant, allowing sorting through multiple columns simultaneously.

@smklein smklein requested a review from davepacheco December 16, 2021 17:38

@davepacheco davepacheco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice! I'm curious how you figured out what the appropriate trait bounds are.

Is it worth adding a test? I'm not sure if it's worth generating a whole fake table with fake data...but on the other hand, I found the boolean filter condition easy to get wrong. It's handy to know it works even with data like (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3) no matter where the marker is in that sequence.

dropshot::PaginationOrder::Ascending => {
if let Some((v1, v2)) = marker {
query = query.filter(c1.eq(v1.clone()).and(c2.gt(v2)));
query = query.or_filter(c1.gt(v1));

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Two functions provided by Diesel actually made these bounds a little easier for me to write, but admittedly different from your original implementation:

https://docs.diesel.rs/master/diesel/prelude/trait.QueryDsl.html#method.or_filter
https://docs.diesel.rs/master/diesel/prelude/trait.QueryDsl.html#method.then_order_by

These are basically "optional versions" of filter and order, respectively, that can reduce the size of arguments passed.

They should be semantically equivalent to the "single-call, larger argument" version, but the trait bounds get a little less hairy.

@david-crespo david-crespo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice!

@smklein

smklein commented Dec 17, 2021

Copy link
Copy Markdown
Collaborator Author

Nice! I'm curious how you figured out what the appropriate trait bounds are.

I mentioned this on our internal chat channel, but:

  • Commenting out most of the implementation, and adding one operation at a time.
  • Using mostly traits from "well-known" spots in Diesel, namely "QueryDSL" and "diesel's helper types".
  • For the most part, ignoring suggestions from rustc.

Is it worth adding a test? I'm not sure if it's worth generating a whole fake table with fake data...but on the other hand, I found the boolean filter condition easy to get wrong. It's handy to know it works even with data like (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3) no matter where the marker is in that sequence.

Sure, added tests for both the single and multi-column cases with a bespoke table for testing.

.execute_async(pool.pool())
.await
.unwrap();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice. this is a good model for future tests

@smklein

smklein commented Dec 17, 2021

Copy link
Copy Markdown
Collaborator Author

Closing this PR, as it was merged in with #512

@smklein smklein closed this Dec 17, 2021
@smklein smklein deleted the pag_multicolumn branch December 17, 2021 18:55
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