-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change how JPluginHelper caches data; support Closures in JCacheControllerCallback #10795
Conversation
I have tested this item ✅ successfully on 8991164 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795. |
} | ||
$db = JFactory::getDbo(); | ||
$query = $db->getQuery(true) | ||
->select('folder AS type, element AS name, params') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbabker Please quoteName the fields.
This PR has received new commits. CC: @Fedik This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795. |
I have tested this item ✅ successfully on 703d721 This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795. |
Changes is OK, I mean to move generating query outside of the method, to ex: protected static function loadQuery($levels) and then run something like: static::$plugins = $cache->get(array(static, 'loadQuery'), array($levels), md5($levels), false); |
It would have to be a public function since the callable is being called from the |
Yes one public static method which return only result of rows. Example: static function loadQuery($levels)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select(array($db->quoteName('folder', 'type'), $db->quoteName('element', 'name'), $db->quoteName('params
')))
->from('#__extensions')
->where('enabled = 1')
->where('type =' . $db->quote('plugin'))
->where('state IN (0,1)')
->where('access IN (' . $levels . ')')
->order('ordering');
$db->setQuery($query);
return $db->loadObjectList();
}
/**
* Loads the published plugins.
*
* @return array An array of published plugins
*
* @since 3.2
*/
protected static function load()
{
if (static::$plugins !== null)
{
return static::$plugins;
}
$user = JFactory::getUser();
$levels = implode(',', $user->getAuthorisedViewLevels());
/** @var JCacheControllerCallback $cache */
$cache = JFactory::getCache('com_plugins', 'callback');
static::$plugins = $cache->get(array(__CLASS__, 'loadQuery'), array($levels), md5($levels), false);
return static::$plugins;
} |
If I'm going to change it (which I don't believe should be part of this PR honestly), I'd rather make it a lambda function versus another public method. Otherwise the load method here should become public too. Making the method to execute the query public might as well make the entire loading mechanism public as well, whereas making it a lambda keeps it internal to the class and any derivatives. |
Lambda may be more appropriate but you can move that method 'loadQuery' to other/new class. I understand that my idea breaks design pattern and it is bad when protected method run public. |
…ork with Closures
This PR has received new commits. This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795. |
I converted it to a lambda function. In converting it, I found that |
I could really use tests here. Getting the callback cache handler to support all callable types will help massively to be able to implement graceful fallbacks against cache related failures in some critical points in the system. |
@mbabker Tried to make a PR against this branch but it came at as 120 changed files, so gave up. Here is the code I wanted to push:
As for the caching mechanism, this works as expected. Only once is the query executed when caching is enabled. |
I have tested this item ✅ successfully on 7b06aec This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795. |
There isn't a hard pressed need to quote everything in the database queries. If that's going to become part of the standard, that needs to be done separately from existing PRs IMO. |
Only names that are reserved keywords need to be name-quoted right ? |
I have tested this item ✅ successfully on 7b06aec Thanks This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795. |
Is this going anywhere or can I close for lack of interest? |
@mbabker It is not going to anywhere it is going into 3.7.0 :-) |
Merged with 3d744c0 |
Summary of Changes
Changes how
JPluginHelper::load()
caches data to use the callback caching controller instead of the generic base class and implements a cache ID based on the authorized access levels for the user.Testing Instructions
With caching enabled, the proper plugins should be loaded for an allowed usergroup list on each request and this data cached.