Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » SimpleTreeDropdownField Speedup?

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: 689 Views
  • Tobi Oetiker
    Avatar
    Community Member
    6 Posts

    SimpleTreeDropdownField Speedup? Link to this post

    I am supporting this site, where there are several instances of SimpleTreeDropdownField used in a Widget configuration screen.
    The widget is used on most pages. Since the site is quite big, this has the unfortunate effect of makeing the navigation in the CMS pretty slow, as the SimpleTreeDropdownField gets generated every time the page switches ...

    I have enabled the $cache property when creating the object, but this does not have any significant effect ...

    Is there a way to add caching the parts of the cms screen ? after all the widget is always the same ...

    cheers
    tobi

  • Tobi Oetiker
    Avatar
    Community Member
    6 Posts

    Re: SimpleTreeDropdownField Speedup? Link to this post

    I wrote this bit here ... would you be interested in integrating it ? Is there some hook to flush the cache when the site tree changes?

    I put a copy on github https://gist.github.com/917288

    --- SimpleTreeDropdownField.php 2011-03-21 21:54:18.000000000 +0100
    +++ /home/speagwww/public_html/dataobject_manager/code/dropdown_fields/SimpleTreeDropdownField.php 2011-04-13 11:44:38.000000000 +0200
    @@ -3,9 +3,8 @@
    class SimpleTreeDropdownField extends HTMLDropdownField
    {
    protected $sourceClass, $labelField, $parentID, $useCache, $filter;
    - private static $cache = array();

    - function __construct($name, $title = "", $sourceClass = "SiteTree", $value = "", $labelField = "Title", $form = null, $emptyString = null, $parentID = 0, $cache = false)
    + function __construct($name, $title = "", $sourceClass = "SiteTree", $value = "", $labelField = "Title", $form = null, $emptyString = null, $parentID = 0, $cache = true)
    {
    $this->labelField = $labelField;
    $this->parentID = $parentID;
    @@ -44,13 +43,16 @@

    private function getCachedHierarchy($parentID) {
    $class = ($this->sourceClass == "SiteTree" || is_subclass_of($this->sourceClass, "SiteTree")) ? "SiteTree" : $this->sourceClass;
    - if (!isset(self::$cache[$class][$parentID])) {
    - if (!isset(self::$cache[$class])) {
    - self::$cache[$class] = array();
    - }
    - self::$cache[$class][$parentID] = $this->getHierarchy($parentID);
    - }
    - return self::$cache[$class][$parentID];
    + $filter = $this->filter ? $this->filter : 'x';
    + $cache = SS_Cache::factory('HierarchyCache');
    + $key = preg_replace('/[^a-zA-Z0-9]/','_',$class."_".$parentID."_".$filter);
    + if (!$data = unserialize($cache->load($key))){
    + $data = $this->getHierarchy($parentID);
    +// Debug::show($data);
    + $cache->save(serialize($data),$key);
    +// Debug::message("Caching ".$key);
    + }
    + return $data;
    }

    private function getHierarchy($parentID, $level = 0)

    689 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.