I'm running out of memory every time I try to create a new record for my Book class. This seems to be because I try to create a set of default BookPage records every time a new Book is saved, which causes SilverStripe to run out of memory:
Fatal error: Allowed memory size of 167772160 bytes exhausted (tried to allocate 91 bytes) in /usr/www/users/ukibum/sapphire/core/model/DataObject.php on line 2758
The first thing I tried was simply to allocate more memory but even with more than 1GB eventually the same thing happens (it just takes a lot longer). This only happens in production where I got more than 90,000 BookPage entries, I tried to purge the db and run the same code on a test server without any problems so it almost seems like SilverStripe is looping through all the records when creating a new one? At first I thought this only happened in Modeladmin but turns out the same thing happens if I try to create and write a new Book entry in any controller.
Not really sure if this is to be expected or what is going on so any advice would be greatly appreciated. Please check this sspaste for what should be all the relevant code:
The script times out while trying to perform the write on line 80.