1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Improving efficiency of XenGallery_Listener::templateCreate

Discussion in 'Media Gallery Resolved Bugs' started by thedude, Apr 11, 2015.

  1. thedude

    thedude Well-Known Member

    1.03 & 1.04

    $_permissionCache (line 9) appears to have been intended to cache XFMG permission values because templateCreate gets called several times during any particular XF page load. However the caching part may have fallen by the wayside if you examine XenGallery_Listener::templateCreate (line 16).

    I've hacked Listener.php to implement the caching so XFMG permissions aren't re-checked for each templateCreate call.

    My altered version of Listener.php, based on 1.04, is attached and here's a explanation of my changes...

    I've added the following variable to cache the array that gets added onto $params in templateCreate
    protected static $_templateParamCache = array();
    In templateCreate, I check if $_templateParamCache has been set yet
    if (empty(self::$_templateParamCache))
    In templateCreate, the second foreach loop is replaced by
    foreach ($preparedPermissions AS $permission)
            self::$_templateParamCache[$permission['id']] = $permission['value'];
    After the closing brace for the initial $_templateParamCache check, there's
    $params += self::$_templateParamCache;
    The array addition above respects existing keys and won't overwrite them.

    Attached Files:

    imthebest and GliX like this.
  2. Chris D

    Chris D XenForo Developer Staff Member

    You're right about it falling by the wayside.

    Actually about a year ago, the code was caching the template params, but I changed the way it worked to simplify it a bit - it seems in that process the caching mechanism was broken.

    Thanks for this.
    thedude and imthebest like this.

Share This Page