Fixed Improving efficiency of XenGallery_Listener::templateCreate

thedude

Well-known member
library/XenGallery/Listener.php
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
Code:
protected static $_templateParamCache = array();

In templateCreate, I check if $_templateParamCache has been set yet
Code:
if (empty(self::$_templateParamCache))
{

In templateCreate, the second foreach loop is replaced by
Code:
foreach ($preparedPermissions AS $permission)
{
        self::$_templateParamCache[$permission['id']] = $permission['value'];
}

After the closing brace for the initial $_templateParamCache check, there's
Code:
$params += self::$_templateParamCache;
The array addition above respects existing keys and won't overwrite them.
 

Attachments

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.
 
Top Bottom