Let’s have many rows in the SQL database where every record has an
image property that holds the path to file in the filesystem. Many database libraries have the ability to set-up hooks that are called right after the row is removed.
Which one of the following patterns is better?
Call hook for every removed row (even when all rows are removed in bulk action) and delete an associated file in that hook function (and fail maybe fail if the file was not removed)
Do not use hooks and instead delete files inside business logic inside function what calls database query (maybe do it inside a transaction to fail if the file was not removed)
Almost every documentation for database libraries warns that using a hook for bulk actions will cause performance issues but I think those performance issues will occur even when you do loop inside eg.