Problem/Motivation

        // If the default query back-end is used generate SQL query strings from
        // the query objects.
        if ($build_info[$index] instanceof Select) {
          $query = clone $build_info[$index];
          $query->preExecute();
          $build_info[$index] = (string)$query;
        }
      }

This code converts the query to a string, but ignores actual arguments entirely.

Proposed resolution

Do it like Drupal 7:

        if ($build_info[$index] instanceof SelectQueryInterface) {
          $query = clone $build_info[$index];
          $query->preExecute();
          $key_data['build_info'][$index] = array(
            'sql' => (string) $query,
            'arguments' => $query->getArguments(),
          );
        }

Remaining tasks

User interface changes

API changes

Comments

wim leers’s picture

Issue tags: +VDC, +D8 cacheability
fabianx’s picture

Oh, wow ... Nice catch!

dawehner’s picture

Issue tags: +Needs tests

Before we forget that.

wim leers’s picture

Issue tags: +Novice, +php-novice
Related issues: +#2452317: Let views result cache use cache contexts

The fix is simple, but the tests may not be. Anyway, tagging. The closely related #2452317: Let views result cache use cache contexts recently was fixed.

catch’s picture

fabianx’s picture

Anonymous’s picture

Assigned: Unassigned »
Anonymous’s picture

Issue tags: +drupaldevdays
keyral’s picture

Status: Active » Needs review
StatusFileSize
new1.29 KB

Hi , My patch to resolved your problem.

Index: core/modules/views/src/Plugin/views/cache/CachePluginBase.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- core/modules/views/src/Plugin/views/cache/CachePluginBase.php	(date 1428925949000)
+++ core/modules/views/src/Plugin/views/cache/CachePluginBase.php	(revision )
@@ -284,16 +284,21 @@
       foreach (array('query', 'count_query') as $index) {
         // If the default query back-end is used generate SQL query strings from
         // the query objects.
+        $query = '';
         if ($build_info[$index] instanceof Select) {
+
+          //Clone Object and preExecute is not perfect !
           $query = clone $build_info[$index];
-          $query->preExecute();
-          $build_info[$index] = (string)$query;
+          //$query->preExecute();
+
+          $key_data['build_info'][$index] = array(
+            'sql' => (string) $query,
+            'arguments' => ($query->getArguments()) ? $query->getArguments() : '',
+          );
         }
+
       }
 
-      $key_data = [
-        'build_info' => $build_info,
-      ];
       // @todo https://www.drupal.org/node/2433591 might solve it to not require
       //    the pager information here.
       $key_data['pager'] = [

Status: Needs review » Needs work

The last submitted patch, 9: views_patch.patch, failed testing.

keyral’s picture

StatusFileSize
new930 bytes
keyral’s picture

Status: Needs work » Needs review
Anonymous’s picture

Assigned: » Unassigned

Status: Needs review » Needs work

The last submitted patch, 11: [core][views][plugin_cache].patch, failed testing.

keyral’s picture

StatusFileSize
new716 bytes
keyral’s picture

Status: Needs work » Needs review
dawehner’s picture

Alright, now we need to have support for a proper test.

jcnventura’s picture

Status: Needs review » Needs work

As per #17, this needs a test.

keyral’s picture

My commit solves the problem ? no ?

fabianx’s picture

#19: Yes, it does! Great work!

But we need to ensure that no-one changes this code back, hence we need a "test-only" patch that shows the tests failing and exposes the bug.

nlisgo’s picture

+++ b/core/modules/views/src/Plugin/views/cache/CachePluginBase.php
@@ -287,7 +287,10 @@ public function generateResultsKey() {
+            'arguments' => $query->getArguments()

We need a comma at the end of the last array element.

See: https://www.drupal.org/coding-standards#array

dimaro’s picture

StatusFileSize
new717 bytes

Add a comma at the end.

dimaro’s picture

Status: Needs work » Needs review
jcnventura’s picture

Status: Needs review » Needs work

Still needs the test.

jcnventura’s picture

StatusFileSize
new4.04 KB

And here's the patch, including the test.. I believe the interdiff is irrelevant in this case.

jcnventura’s picture

Status: Needs work » Needs review
nlisgo’s picture

@jcnventura thanks for the test on this. It would be useful to provide a test only patch for this.

jcnventura’s picture

StatusFileSize
new3.34 KB
new4.04 KB

Uploading a test-only patch as requested.

The last submitted patch, 28: views_result_cache-2442769-28-tests.patch, failed testing.

nlisgo’s picture

RTBC +1

I have read all of the lines of the patch and would recommend that this can be accepted as is.

nlisgo’s picture

Status: Needs review » Needs work
+++ b/core/modules/views/src/Tests/Plugin/CacheTest.php
@@ -101,6 +102,84 @@ public function testTimeResultCaching() {
+        'output_lifespan' => '3600'

Just noticed a small thing.

needs a comma at the end of the line

dawehner’s picture

The test coverage really looks great!

+++ b/core/modules/views/src/Tests/Plugin/CacheTest.php
@@ -101,6 +102,84 @@ public function testTimeResultCaching() {
+    // Check that we can find the test filter plugin.
+    $plugin = $this->container->get('plugin.manager.views.filter')->createInstance('test_filter');
+    $this->assertTrue($plugin instanceof FilterPlugin, 'Test filter plugin found.');

Yeah, IMHO this doesn't add that much of test coverage. I guess you needed it during development of the test ...

pec’s picture

Status: Needs work » Needs review
StatusFileSize
new4.87 KB
new5.57 KB

Added the commas where needed

Status: Needs review » Needs work

The last submitted patch, 33: views_result_cache-2442769-32-complete.patch, failed testing.

The last submitted patch, 33: views_result_cache-2442769-32-test.patch, failed testing.

Status: Needs work » Needs review
dimaro’s picture

StatusFileSize
new990 bytes
new6.22 KB

Create new version of patch removing deprecated drupal_render() function.

dimaro’s picture

I have seen that in some areas of the code short array syntax is used.

We should extend throughout the test?

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

RTBC

#32: Explicitly checking for the filter plugin does make sense here IMHO as we rely on it later and that is what asserts are for.

nlisgo’s picture

RTBC +1

  • catch committed 7739453 on 8.0.x
    Issue #2442769 by keyral, jcnventura, dimaro, pec: Views result cache...
catch’s picture

Status: Reviewed & tested by the community » Fixed

So fix is the same as 7.x, and the test coverage looks exactly what we need.

Committed/pushed to 8.0.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.