Commit d8181f8f authored by webchick's avatar webchick
Browse files

Issue #2140051 by damiankloip: Remove views_cache_get/set functions.

parent 78c933eb
......@@ -102,6 +102,13 @@ abstract class DisplayPluginBase extends PluginBase {
*/
protected $usesAreas = TRUE;
/**
* Static cache for unpackOptions, but not if we are in the UI.
*
* @var array
*/
protected static $unpackOptions = array();
/**
* Constructs a new DisplayPluginBase object.
*
......@@ -124,12 +131,10 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio
// Load extenders as soon as possible.
$this->extender = array();
$extenders = views_get_enabled_display_extenders();
if (!empty($extenders)) {
if ($extenders = Views::getEnabledDisplayExtenders()) {
$manager = Views::pluginManager('display_extender');
foreach ($extenders as $extender) {
$plugin = $manager->createInstance($extender);
if ($plugin) {
if ($plugin = $manager->createInstance($extender)) {
$plugin->init($this->view, $this);
$this->extender[$extender] = $plugin;
}
......@@ -148,23 +153,23 @@ public function initDisplay(ViewExecutable $view, array &$display, array &$optio
unset($options['defaults']);
}
// Cache for unpackOptions, but not if we are in the ui.
static $unpack_options = array();
if (empty($view->editing)) {
$cid = 'unpackOptions:' . hash('sha256', serialize(array($this->options, $options)));
if (empty($unpack_options[$cid])) {
$cache = views_cache_get($cid, TRUE);
$skip_cache = \Drupal::config('views.settings')->get('skip_cache');
if (empty($view->editing) || !$skip_cache) {
$cid = 'unpackOptions:' . hash('sha256', serialize(array($this->options, $options))) . ':' . \Drupal::languageManager()->getLanguage()->id;
if (empty(static::$unpackOptions[$cid])) {
$cache = \Drupal::cache('views_info')->get($cid);
if (!empty($cache->data)) {
$this->options = $cache->data;
}
else {
$this->unpackOptions($this->options, $options);
views_cache_set($cid, $this->options, TRUE);
\Drupal::cache('views_info')->set($cid, $this->options);
}
$unpack_options[$cid] = $this->options;
static::$unpackOptions[$cid] = $this->options;
}
else {
$this->options = $unpack_options[$cid];
$this->options = static::$unpackOptions[$cid];
}
}
else {
......
......@@ -67,18 +67,28 @@ protected function setUp() {
->setConstructorArgs(array(array(), 'path_base', array(), $this->routeProvider, $this->state))
->setMethods(NULL)
->getMock();
$this->setupAccessPluginManager();
$this->setupContainer();
}
/**
* Setup access plugin manager in a Drupal class.
* Setup access plugin manager and config factory in the Drupal class.
*/
public function setupAccessPluginManager() {
public function setupContainer() {
$this->accessPluginManager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
->disableOriginalConstructor()
->getMock();
$container = new ContainerBuilder();
$container->set('plugin.manager.views.access', $this->accessPluginManager);
$config = array(
'views.settings' => array(
'skip_cache' => TRUE,
'display_extenders' => array(),
),
);
$container->set('config.factory', $this->getConfigFactoryStub($config));
\Drupal::setContainer($container);
}
......
......@@ -1355,52 +1355,3 @@ function views_element_validate_tags($element, &$form_state) {
}
}
}
/**
* Set a cached item in the views cache.
*
* This is just a convenience wrapper around cache_set().
*
* @param $cid
* The cache ID of the data to store.
* @param $data
* The data to store in the cache. Complex data types will be automatically serialized before insertion.
* Strings will be stored as plain text and not serialized.
* @param $use_language
* If TRUE, the data will be cached specific to the currently active language.
*/
function views_cache_set($cid, $data, $use_language = FALSE) {
if (\Drupal::config('views.settings')->get('skip_cache')) {
return;
}
if ($use_language) {
$cid .= ':' . language(Language::TYPE_INTERFACE)->id;
}
cache('views_info')->set($cid, $data);
}
/**
* Return data from the persistent views cache.
*
* This is just a convenience wrapper around cache_get().
*
* @param int $cid
* The cache ID of the data to retrieve.
* @param bool $use_language
* If TRUE, the data will be requested specific to the currently active language.
*
* @return stdClass|bool
* The cache or FALSE on failure.
*/
function views_cache_get($cid, $use_language = FALSE) {
if (\Drupal::config('views.settings')->get('skip_cache')) {
return FALSE;
}
if ($use_language) {
$cid .= ':' . language(Language::TYPE_INTERFACE)->id;
}
return cache('views_info')->get($cid);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment