Skip to content

Use diff based updating for project_authorizations

Currently User#refresh_project_authorizations essentially takes these steps:

  1. Start a transaction
  2. Remove existing rows for a user
  3. Insert all fresh rows for a user
  4. Commit

This can lead to a high amount of dead tuples whenever users with access to many projects have their list updated.

To deal with this we should change this method so that it:

  1. Only removes rows for which access was removed, or for which the access level was changed
  2. Only inserts rows for which access was granted, or the access level was changed

This means that if user A is granted access to project B only 1 new row is added, instead of X rows being removed and Y new rows being inserted.