From b1102f73025f6484d6733c4f778272943369780a Mon Sep 17 00:00:00 2001
From: dereine <dereine@99340.no-reply.drupal.org>
Date: Sun, 22 Jul 2012 22:09:27 +0200
Subject: [PATCH] Issue #1566394 by dawehner | rszrama: Fixed
 views_handler_relationship_groupwise_max() does not export its
 subquery_string().

---
 ...ews_handler_relationship_groupwise_max.inc | 33 ++++++++++---------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/handlers/views_handler_relationship_groupwise_max.inc b/handlers/views_handler_relationship_groupwise_max.inc
index eb1432b6ee80..a3e7f6b2e911 100644
--- a/handlers/views_handler_relationship_groupwise_max.inc
+++ b/handlers/views_handler_relationship_groupwise_max.inc
@@ -151,21 +151,6 @@ function options_form(&$form, &$form_state) {
     );
   }
 
-  /**
-   * Perform any necessary changes to the form values prior to storage.
-   * There is no need for this function to actually store the data.
-   *
-   * Generate the subquery string when the user submits the options, and store
-   * it. This saves the expense of generating it when the view is run.
-   */
-  function options_submit(&$form, &$form_state) {
-    // Get the new user options from the form values.
-    $new_options = $form_state['values']['options'];
-    $subquery = $this->left_query($new_options);
-    // Add the subquery string to the options we're about to store.
-    $this->options['subquery_string'] = $subquery;
-  }
-
   /**
    * Helper function to create a pseudo view.
    *
@@ -179,6 +164,14 @@ function get_temporary_view() {
     return $view;
   }
 
+  /**
+   * When the form is submitted, take sure to clear the subquery string cache.
+   */
+  function options_form_submit(&$form, &$form_state) {
+    $cid = 'views_relationship_groupwise_max:' . $this->view->name . ':' . $this->view->current_display . ':' . $this->options['id'];
+    cache_clear_all($cid, 'cache_views_data');
+  }
+
   /**
    * Generate a subquery given the user options, as set in the options.
    * These are passed in rather than picked up from the object because we
@@ -362,7 +355,15 @@ function query() {
     }
     else {
       // Get the stored subquery SQL string.
-      $def['left_query'] = $this->options['subquery_string'];
+      $cid = 'views_relationship_groupwise_max:' . $this->view->name . ':' . $this->view->current_display . ':' . $this->options['id'];
+      $cache = cache_get($cid, 'cache_views_data');
+      if (isset($cache->data)) {
+        $def['left_query'] = $cache->data;
+      }
+      else {
+        $def['left_query'] = $this->left_query($this->options);
+        cache_set($cid, $def['left_query'], 'cache_views_data');
+      }
     }
 
     if (!empty($def['join_handler']) && class_exists($def['join_handler'])) {
-- 
GitLab