We had a problem where the Solr Views cache was returning wrong results when we used exposed filters. The cache was not tracking distinct result sets based on all possible parameters. I tracked the problem down to the fact that get_results_key() didn't have all the information it needed to create a unique results key for each possible result set. My fix for this, included in the patch here, was to add the query and params arrays to the $view->build_info array as those really are build parameters. This way, the caching code can track results for all possible distinct result sets properly.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Scott Reynolds’s picture

Status: Needs review » Needs work

Perhaps I am looking at the wrong thing. This is views_plugin_cache::get_results_key

function get_results_key() {
    global $user;

    if (!isset($this->_results_key)) {
      $key_data = array(
        'build_info' => $this->view->build_info,
        'roles' => array_keys($user->roles),
        'super-user' => $user->uid == 1, // special caching for super user.
        'language' => $GLOBALS['language'],
      );
      foreach (array('exposed_info', 'page', 'sort', 'order') as $key) {
        if (isset($_GET[$key])) {
          $key_data[$key] = $_GET[$key];
        }
      }

      $this->_results_key = $this->view->name . ':' . $this->display->id . ':results:' . md5(serialize($key_data));
    }

    return $this->_results_key;
  }

both query and apachesolr_params aren't in there.

Does this mean we need to override get_results_key in the cache plugin?

mgriego’s picture

Status: Needs work » Needs review

No, we don't need to override get_results_key. I specifically tried to avoid that actually. The query and apachesolr_params are added to $view->build_info, which is the first element added to $key_data.

JeremyFrench’s picture

Status: Needs review » Needs work

Things may have moved on a bit in views since this bugs was raised. I have had more luck adding a method get_cache_info() to the apachesolr_views_query object. Get_results_key() now calls this and if not present it will not cache.

If I get some robust code in there I'll submit a patch.

JeremyFrench’s picture

Attached is patch, first patch I have done from git so apologies if formatting is wrong.

JeremyFrench’s picture

Status: Needs work » Needs review
mgriego’s picture

That looks right to me. I'll be testing that patch in our environment this week and will report back how it works.

mgriego’s picture

Status: Needs review » Reviewed & tested by the community

This does appear to be working for us.

caminadaf’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

This is not working on 7.x, a views cache plugin class needs to be implemented.

caminadaf’s picture

Status: Needs work » Needs review
FileSize
2.4 KB

I took the liberty of creating the cache plugin and doing a get_cache_key for this module, since apachesolr_views' query variable is not an object, but a string.

Status: Needs review » Needs work

The last submitted patch, 9: apachesolr_views_results_cache-882424-9.patch, failed testing.

caminadaf’s picture

Status: Needs work » Needs review

I mistakenly triggered a test build, but there are no tests for this module... Moving back to review

The last submitted patch, 4: patch-418774-2.patch, failed testing.

The last submitted patch, apachesolr_views_results_cache.patch, failed testing.

MiroslavBanov’s picture

Looks fine.

But I almost never use views cache, and I am not using this module currently, so will wait for other reviewer to RTBC.

caminadaf’s picture

Updating the patch since the typehint broke the fix