Skip to content

Bulk inserts: Consider disallowing callback definitions

This was broken out of #36992 (closed) after reviewing the first POC in a debrief meeting.

The main problem with the POC was the difficulty of firing AR callbacks in a reliable way before and after batching the SQL. An obvious solution out of this is: no callbacks, no problem. To that end we suggest that if we were able (and willing) to identify certain "offenders" we know to perform particularly bad during imports, then we could add a guard that prevents developers from defining any AR callbacks on them to begin with. That way, we can then provide a dedicated code path for those relations during import where we simple batch-insert them row-wise, possibly bypassing AR altogether.

This has drawbacks as well of course, such as:

  • the inability to define callbacks on certain relations but not others may be surprising to developers
  • it would increase the complexity of the importer, since we would have to account for both batched inserts and "normal" inserts

The current proposal is to define a new concern BulkInsertable that "white lists" a given relation to be permitted for bulk inserts as described in #196844 (closed). Upon inclusion of that mixin it would perform checks to verify that the model is actually bulk-insertable by not defining any custom callbacks or validations.

Edited by Matthias Käppler