Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Memory Issue with Sortable Data Objects

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 565 Views
  • elgordo
    Avatar
    Community Member
    70 Posts

    Memory Issue with Sortable Data Objects Link to this post

    I've recently being trying to create a large SilverStripe site by importing all of my Flickr photographs as DataObjects (around 60000). This is primarily so I can do things like database queries on the Exif data, e.g. find all photographs taken in the morning with an aperture of less than f8.

    My import process kept crashing with a memory issue, and the symptom I was seeing was memory jumping from 29M to > 128M with the saving of a single image. I eventually tracked it down to the onBeforeWrite method of File, and looking through the DataObject decorators, the one that was failing was SortableDataObject.

    The problematic method is below:

    public function onBeforeWrite()
       {
          if(!$this->owner->ID) {
             if($peers = DataObject::get($this->owner->class))
                $this->owner->SortOrder = $peers->Count()+1;
          }
       }   

    The line

             if($peers = DataObject::get($this->owner->class))

    is loading *all* of the DataObjects of a particular class (in my case, Image), and then setting the SortOrder of the new one to be one more than the total count of these DataObjects. As a result as a site grows, more memory will be used up when saving a new DataObject, eventually resulting in a save becoming impossible due to memory constraints.

    Cheers

    Gordon

  • elgordo
    Avatar
    Community Member
    70 Posts
  • elgordo
    Avatar
    Community Member
    70 Posts

    Re: Memory Issue with Sortable Data Objects Link to this post

    I've now imported 26000 Dataobjects representing flickr images with no apparent memory issues, the import process is sitting around 30M of memory use.

    565 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.