Not a bug Deleting a parent node with large amount of child nodes causes allowed memory size exception

TickTackk

Well-known member
Affected version
2.2.4
PHP:
    protected function deleteChildren()
    {
        $finder = $this->entity->em()->getFinder($this->entity->structure()->shortName);
        $finder->where($this->config['parentField'], $this->entity->getEntityId());
        
        foreach ($finder->fetch() AS $child)
        {
            /** @var Entity $child */
            $treeStructure = $child->getBehavior('XF:TreeStructured');
            $treeStructure->setOption('deleteChildAction', $this->getOption('deleteChildAction'));
            $treeStructure->setOption('rebuildCache', false);
            $child->delete(true, false);
        }
    }
under src/XF/Behavior/TreeStructured.php.
 
How many children does this node have?

There is generally an expectation that we can load all nodes at any given time as there are common places we do this (the forum list being the most obvious place, though there are many others). Therefore, it's not unreasonable to load a subset of the node tree at a given time.

Note that debug mode can increase memory usage due to things like query logging, so this is something that needs to be taken into account if a memory error is triggered.
 
How many children does this node have?
I don't recall the exact number it was definitely above 100 with each forum having at least one thread and maybe the child forum having another forum.

Note that debug mode can increase memory usage due to things like query logging, so this is something that needs to be taken into account if a memory error is triggered.
I'm guessing the logging of the query would have been the issue here mostly because when listing out 300+ nodes I don't get any memory error.
 
Hundreds of nodes really shouldn't be a huge problem. If you had 300 nodes in total and even if each of those led to a total of 10 entities (2 is closer to realistic for the node and type-specific record), you'd have instantiated 3000 entities. If we assume each takes up 10KB of memory (in a very quick and non-scientific test, I had them taking about 9KB each), you're in the vicinity of 30MB of memory and well short of the standard 128MB limit.

Thread deletion is handled by a job so that shouldn't trigger much additional memory (though the job can be kicked off immediately).

So it does seem like something else is likely taking up a fair amount of memory. It's worth noting that we do try to limit the size of the query log once it gets over 150 queries, but it's still something that only exists in debug mode and there's no guarantee of how much memory it might take up there.

If we start hearing about this on production forums that might be something to look into further.
 
Back
Top Bottom