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

updateSortingOrder for areas allows re-sorting in-place #293

Merged
merged 1 commit into from
May 19, 2023

Conversation

zichongkao
Copy link
Contributor

In response to problem noted here: OpenBeta/open-tacos#696 (comment)

In testing, I'm hitting the duplicate index error for leftRightIndex. I think it's because I'm sending [{areaId: .., leftRightIndex: 0}, {areaId: .., leftRightIndex: 1}, .., {areaId: .., leftRightIndex: <# of childareas -1>}] and when we try to set the leftRightIndex to be 0 for the first item, there is already another entry in the db with leftRightIndex 0, so throws the error even though later on, that item's leftRightIndex will replaced by a different entry. I could reset everything to -1 and then reassign, but it's not that elegant.

In the end, I couldn't find a better way than resetting everything -1. I looked into seeing if Mongo supports deferred constraints to get it to check the uniqueness of leftRightIndex only after all the bulk updates are complete. I also looked into whether Mongo could update multiple documents atomically, to avoid the intermediate state where there is a duplicate index. Both didn't work out.

@zichongkao zichongkao force-pushed the kao-updatesortingorder branch 2 times, most recently from 08c53e2 to 7ef186a Compare May 18, 2023 17:40
@vnugent
Copy link
Contributor

vnugent commented May 19, 2023

Nice workaround!

@vnugent vnugent merged commit 2589e6b into develop May 19, 2023
l4u532 pushed a commit to l4u532/openbeta-graphql that referenced this pull request Dec 10, 2023
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.

2 participants