Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Change how JPluginHelper caches data; support Closures in JCacheControllerCallback #10795

wants to merge 3 commits into from

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Jun 12, 2016

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.

@Fedik
Copy link
Member

Fedik commented Jun 12, 2016

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')
Copy link
Contributor

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.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @Fedik


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795.

@ggppdk
Copy link
Contributor

ggppdk commented Jun 25, 2016

I have tested this item ✅ successfully on 703d721

Tested various backend / frontend views and forms,
works as expected, only 1st call executes the query, all subsequent method calls use the cached data


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795.

@csthomas
Copy link
Contributor

Changes is OK,
but IMHO would be better to generate query only if cache does not exists.

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);

@mbabker
Copy link
Contributor Author

mbabker commented Jun 27, 2016

It would have to be a public function since the callable is being called from the JCacheControllerCallback class. Unless we change it to use a lambda function I wouldn't suggest any other changes at all at this point as I wouldn't suggest opening the public API to expose that result set directly.

@csthomas
Copy link
Contributor

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;
}

@mbabker
Copy link
Contributor Author

mbabker commented Jun 27, 2016

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.

@csthomas
Copy link
Contributor

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.
I admit you are right.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @Fedik, @ggppdk


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795.

@mbabker
Copy link
Contributor Author

mbabker commented Jun 27, 2016

I converted it to a lambda function. In converting it, I found that JCacheControllerCallback would not support lambda functions; it does now. So there's your bonus feature for this patch.

@mbabker mbabker changed the title Change how JPluginHelper::load() caches data Change how JPluginHelper caches data; support Closures in JCacheControllerCallback Jun 27, 2016
@mbabker
Copy link
Contributor Author

mbabker commented Jul 14, 2016

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.

@roland-d
Copy link
Contributor

@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:

->from($db->quoteName('#__extensions'))
->where($db->quoteName('enabled') . ' = 1')
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('state') . ' IN (0,1)')
->where($db->quoteName('access') . ' IN (' . $levels . ')')
->order($db->quoteName('ordering'));

As for the caching mechanism, this works as expected. Only once is the query executed when caching is enabled.

@roland-d
Copy link
Contributor

I have tested this item ✅ successfully on 7b06aec

Caching mechanism, this works as expected. Only once is the query executed when caching is enabled.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795.

@mbabker
Copy link
Contributor Author

mbabker commented Jul 15, 2016

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.

@ggppdk
Copy link
Contributor

ggppdk commented Jul 15, 2016

Only names that are reserved keywords need to be name-quoted right ?
using this in all cases becomes unnecessary more complex looking , thus more difficult to read, are we worried that new DB versions will add more "keywords" ? or playing safe for "all" DBs ?

@pritalpatel
Copy link

pritalpatel commented Jul 16, 2016

I have tested this item ✅ successfully on 7b06aec

I have Tested content and User backend views. It's work normally. 😄

Thanks


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10795.

@mbabker
Copy link
Contributor Author

mbabker commented Aug 13, 2016

Is this going anywhere or can I close for lack of interest?

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Aug 13, 2016
@rdeutz rdeutz added this to the Joomla 3.7.0 milestone Aug 14, 2016
@rdeutz
Copy link
Contributor

rdeutz commented Aug 14, 2016

@mbabker It is not going to anywhere it is going into 3.7.0 :-)

wilsonge added a commit that referenced this pull request Aug 18, 2016
@wilsonge
Copy link
Contributor

Merged with 3d744c0

@wilsonge wilsonge closed this Aug 18, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Aug 18, 2016
@mbabker mbabker deleted the pluginDataCaching branch August 18, 2016 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants