So let's say I have a user table tied to a media storage table. Every time a user uploads a video I want their user id to be attached to a row in the media table. Also say that it takes an arbitrarily long amount of time to remove a user. Lets say 15s for examples sake. If a user hits upload at 5s of the 15s run and the server has already started the process to remove the user, will a query to see if the user exists still be true? Does transaction locking apply to the whole table?The same for creating a user. Let's say I create a test to run 2 user creations in parallel and by some fluke the test generates the same username for both (assuming it should be unique). While I can place a check in the create user route to see if a user with that username already exists, 2 calls running close enough would both return true. Yes, I can add a constraint to the table to prevent non-unique usernames, but I'd much rather throw my own error, than let the call get all the way to the database before throwing an error.Is there a way to "lock" the whole user db table so when a user transaction is happening any call to the table must wait for it to finish?OR am I thinking of locks and transactions completely wrong?I was thinking of using a status column as I know sequelize allows for row locks, but I wasn't sure about the situation described above.
Submitted December 27, 2019 at 02:59AM by blindly_running
No comments:
Post a Comment