harvard-lil / perma

Indelible links
424 stars 71 forks source link

Bonus links and transactions sketch #3648

Open jcushman opened 3 weeks ago

jcushman commented 3 weeks ago

This is a quick sketch to try to reduce opportunities for deadlocks in saving or moving links.

Sketch:

jcushman commented 3 weeks ago

Be a notch more selective in when to update bonus_links in Folder.save() -- I'm not sure how often this matters.

Oh, I suspect this would have made the difference here! The deadlock is on this line:

image

And the deadlocked call was "UPDATE "perma_linkuser" SET "bonus_links" = NULL WHERE "perma_linkuser"."id" = %s", which suggests bonus_links weren't in play. So moving the save() up into the if block above would have prevented it entirely.


I think the other important question is, is this select_for_update still doing anything?

image

If that was just to protect the bonus_links count I think we can lose it, but maybe it's for something else too, in which case we could make it more specific.