Skip to content

Remove `ProjectAuthorization.insert_authorizations` method

What does this MR do and why?

This MR does multiple things:

  • Removes the ProjectAuthorization.insert_authorizations method - because this method acts the same way as the Rails's built-in insert_all method, so there is no need to keep and maintain another method that does the same thing.
Query generated on ProjectAuthorization.insert_all
ProjectAuthorization.insert_all([{user_id: 1, project_id: 1, access_level: 20}, {user_id: 108, project_id:48, access_level: 20}])

INSERT INTO "project_authorizations" ("user_id","project_id","access_level") VALUES (1, 1, 20), (108, 48, 20) ON CONFLICT ("user_id","project_id","access_level") DO NOTHING RETURNING "user_id","project_id","access_level"
Query generated on ProjectAuthorization.insert_authorizations
ProjectAuthorization.insert_authorizations([[108, 47, 20]])

INSERT INTO "project_authorizations" ("user_id","project_id","access_level") VALUES (108, 47, 20) ON CONFLICT DO NOTHING

We can see that the query differs slightly only in the ON CONFLICT DO NOTHING part, but the unique key on project_authorizations table is on (user_id, project_id, access_level) alone, so being explicit about ON CONFLICT ("user_id","project_id","access_level") DO NOTHING and just mentioning ON CONFLICT DO NOTHING means the same thing on this table. So we are safe to use insert_all in place of insert_authorizations.

  • insert_authorizations however, allowed to bulk insert records in batches of 1000 for performance, so we have now introduced insert_all_in_batches that simply calls insert_all internally, for each batch so that insert_authorizations and insert_all_in_batches behave exactly the same way.

  • And now that we have insert_all_in_batches, which does batched inserts, we can replace usages of both ProjectAuthorization.insert_authorizations and ProjectAuthorization.insert_all with ProjectAuthorization.insert_all_in_batches

(no changelog added as this is only a refactor in the internal implementation detail)

Screenshots or screen recordings

These are strongly recommended to assist reviewers and reduce the time to merge your change.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Manoj M J

Merge request reports

Loading