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

fix: Fixed LastMade recipes sorting order #4980

Merged

Conversation

PancakeZik
Copy link
Contributor

What this PR does / why we need it:

Fixes postgres incorrectly sorting null as the most recent.

-->

Which issue(s) this PR fixes:

Fixes #4937

Special notes for your reviewer:

The original problem was only reproduced in postgres - in sqlite it was fine.

Testing

Ran checks

Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

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

I don't think we want to bake this into the repository on the backend. The backend already supports specifying null ordering. Can we make this change to the frontend query instead?

From the API docs:
image

@PancakeZik
Copy link
Contributor Author

PancakeZik commented Jan 29, 2025 via email

@michael-genson
Copy link
Collaborator

You can probably add some logic here that handles null sorting:

async function fetchRecipes(pageCount = 1) {
return await fetchMore(
page.value,
perPage * pageCount,
props.query?.orderBy || preferences.value.orderBy,
props.query?.orderDirection || preferences.value.orderDirection,
props.query,
// we use a computed queryFilter to filter out recipes that have a null value for the property we're sorting by
queryFilter.value
);
}

You can calculate the order by null, something like:

const orderDir = props.query?.orderDirection || preferences.value.orderDirection;
const orderByNull = orderDir === "asc" ? "first" : "last"

Then pass orderDir and orderByNull to fetchMore. You will also have to modify fetchMore to accept null ordering (see the API docs)

@PancakeZik
Copy link
Contributor Author

See what you think now?

Copy link
Collaborator

@michael-genson michael-genson 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! Just a couple small code cleanliness things

@michael-genson michael-genson enabled auto-merge (squash) January 29, 2025 22:58
michael-genson
michael-genson previously approved these changes Jan 29, 2025
Copy link
Collaborator

@michael-genson michael-genson left a comment

Choose a reason for hiding this comment

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

Looks great now, thanks for this! I think since I pushed the last bit someone else will have to approve it, but putting my approval here anyway for visibility

@michael-genson michael-genson merged commit a52fda7 into mealie-recipes:mealie-next Jan 30, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Sorting by "Last Made" Places "Never Made" Recipes Incorrectly
3 participants