In the boot method of the Thread model, the $thread->replies->each->delete() part produces too many queries which gives rise to performance issues especially when a thread has too many replies. When you call each, it runs three query for deleting each reply (one to select thread, one to decrease the replies_count field on the threads table, one to actually delete the reply). Wouldn't calling $thread->replies()->delete() be a better approach? i.e.
In the boot method of the Thread model, the
$thread->replies->each->delete()
part produces too many queries which gives rise to performance issues especially when a thread has too many replies. When you calleach
, it runs three query for deleting each reply (one to select thread, one to decrease the replies_count field on the threads table, one to actually delete the reply). Wouldn't calling$thread->replies()->delete()
be a better approach? i.e.