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

use upsert instead of 2 queries per row #5342

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Oct 11, 2023

WHY

BEFORE - What was wrong? What was happening before this PR?

We were using DB:: transactions to wrap the reordering updates on database.
We did this because we were looping over all the tree elements and doing two database queries for each of the elements.

Wrapping the queries in a DB transaction does not make less queries, it just means that if any of the queries fail we are able to revert the whole process. So for ordering 10 items, we would still make 20 queries.

I switched to use a combination of upsert and validating the ids to do the WHOLE process in only two queries.

  • One query gets the db id's
  • One query updates all the values

If we do it all in one query, if the query fails it fails as a whole, and we don't need to wrap this in a transaction.

This would allow us to also fix some compatibility issue with MongoDB reported in #4909

@pxpm pxpm added Minor Bug A bug that happens only in a very niche or specific use case. Priority: SHOULD labels Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Bug A bug that happens only in a very niche or specific use case. Priority: SHOULD
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants