Prevent deadlocks by always updating items in the same order.
Test Plan
The tests are a bit fragile since they are testing a concurrency issue. But when running them without the fix, there is almost always at least one failure on my machine (with pgsql running on a tmpfs).
Migrated from D1218 (view on Phabricator)