mirror of
https://github.com/matze/wastebin.git
synced 2026-04-25 00:25:59 +03:00
[PR #75] Avoid ID clashes #145
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/wastebin-matze#145
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/matze/wastebin/pull/75
Author: @cgzones
Created: 10/26/2024
Status: 🔄 Open
Base:
master← Head:id_clash📝 Commits (1)
4ead289Avoid ID clashes📊 Changes
3 files changed (+60 additions, -43 deletions)
View changed files
📝
crates/wastebin_core/src/db.rs(+57 -37)📝
crates/wastebin_server/src/handlers/insert/api.rs(+1 -3)📝
crates/wastebin_server/src/handlers/insert/form.rs(+2 -3)📄 Description
Currently the the ID for a new paste is randomly generated in the caller of the database insert() function. Then the insert() function tries to insert a new row into the database with that passed ID. There can however already exists a paste in the database with the same ID leading to an insert failure, due to a constraint violation due to the PRIMARY KEY attribute. Checking prior the the INSERT via a SELECT query would open the window for a race condition.
A failure to push a new paste is quite severe, since the user might have spent some some to format the input.
Generate the ID in a loop inside, until the INSERT succeeds.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.