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

[Issue #1467] Add order_by support for more fields #1481

Merged
merged 26 commits into from
Mar 19, 2024

Conversation

chouinar
Copy link
Collaborator

Summary

Fixes #1467

Time to review: 10 mins

Changes proposed

Added the ability to order_by several more fields

Updates to test structure, continuing a pattern from the parent PR

Context for reviewers

Except for relevancy (which is its own separate ticket if we do it prior to a search index), this should cover all the sorting needs for search in the near term.

One callout is that sorting always shoves null values to the end now, regardless of whether they are ascending or descending (by default, Postgres considers null to be the largest value).

Additional information

Did some local testing of performance with the queries we actually use, and sorting by any of these fields has effectively the same performance cost, and adding an index to the un-indexed ones didn't seem to change that.

Copy link
Collaborator

@coilysiren coilysiren left a comment

Choose a reason for hiding this comment

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

Makes sense to me!

# means we can't determine how to sort / need to correct
# the mismatch.
msg = f"Unconfigured sort_by parameter {pagination.order_by} provided, cannot determine how to sort."
raise Exception(msg)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like is should raise a HTTP 400, not a HTTP 500? Do you have a class for that?

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 wanted to return a 500 here, if this happens, it is because of a bug in our code. This means our API allows you to pass in a field to sort by that we haven't implemented.

Copy link
Collaborator

@jamesbursa jamesbursa left a comment

Choose a reason for hiding this comment

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

Looks good!

# This determines whether we use ascending or descending when building the query
sort_fn = asc if pagination.is_ascending else desc

match pagination.order_by:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Neat to see match being used, I haven't used it yet.

Base automatically changed from chouinar/1167-add-filtering to main March 18, 2024 15:26
@chouinar chouinar merged commit 4686472 into main Mar 19, 2024
8 checks passed
@chouinar chouinar deleted the chouinar/1467-order-by-additions branch March 19, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Add additional order_by fields to the API
4 participants