MDL-53272 search: Remove search results cache

This commit is contained in:
David Monllao 2016-03-24 16:28:33 +08:00
parent 54abd66aca
commit 9470e4d1ed
8 changed files with 1 additions and 109 deletions

View File

@ -59,7 +59,6 @@ $string['cachedef_plugin_functions'] = 'Plugins available callbacks';
$string['cachedef_plugin_manager'] = 'Plugin info manager';
$string['cachedef_questiondata'] = 'Question definitions';
$string['cachedef_repositories'] = 'Repositories instances data';
$string['cachedef_search_results'] = 'Search results user data';
$string['cachedef_grade_categories'] = 'Grade category queries';
$string['cachedef_string'] = 'Language string cache';
$string['cachedef_tags'] = 'Tags collections and areas';

View File

@ -263,14 +263,6 @@ $definitions = array(
'staticacceleration' => true,
),
// Caches search results.
'search_results' => array(
'mode' => cache_store::MODE_SESSION,
'simplekeys' => true,
'staticacceleration' => true,
'staticaccelerationsize' => 3
),
// Grade categories. Stored at session level as invalidation is very aggressive.
'grade_categories' => array(
'mode' => cache_store::MODE_SESSION,

View File

@ -54,10 +54,6 @@ $observers = array(
'eventname' => '\core\event\user_updated',
'callback' => 'core_badges_observer::profile_criteria_review',
),
array(
'eventname' => '\core\event\search_indexed',
'callback' => 'core_search_observer::invalidate_caches',
),
);
// List of all events triggered by Moodle can be found using Events list report.

View File

@ -64,10 +64,6 @@ if ($data = $mform->get_data()) {
if (!empty($data->all) || $anydelete) {
echo $OUTPUT->notification(get_string('deleted', 'report_search'), 'notifysuccess');
// Purge the cache.
$cache = \cache::make('core', 'search_results');
$cache->purge();
}
}

View File

@ -402,17 +402,6 @@ class manager {
public function search(\stdClass $formdata) {
global $USER;
$cache = \cache::make('core', 'search_results');
// Generate a string from all query filters
// Not including $areascontext here, being a user cache it is not needed.
$querykey = $this->generate_query_key($formdata, $USER->id);
// Look for cached results before executing it.
if ($results = $cache->get($querykey)) {
return $results;
}
// Clears previous query errors.
$this->engine->clear_query_error();
@ -424,40 +413,9 @@ class manager {
$docs = $this->engine->execute_query($formdata, $areascontexts);
}
// Cache results.
$cache->set($querykey, $docs);
return $docs;
}
/**
* We generate the key ourselves so MUC knows that it contains simplekeys.
*
* @param stdClass $formdata
* @return string
*/
protected function generate_query_key($formdata) {
global $USER;
// Empty values by default (although q should always have a value).
$fields = array('q', 'title', 'areaid', 'timestart', 'timeend', 'page');
// Just in this function scope.
$params = clone $formdata;
foreach ($fields as $field) {
if (empty($params->{$field})) {
$params->{$field} = '';
}
}
// Although it is not likely, we prevent cache hits if available search areas change during the session.
$enabledareas = implode('-', array_keys(static::get_search_areas_list(true)));
return md5($params->q . 'userid=' . $USER->id . 'title=' . $params->title . 'areaid=' . $params->areaid .
'timestart=' . $params->timestart . 'timeend=' . $params->timeend . 'page=' . $params->page .
$enabledareas);
}
/**
* Merge separate index segments into one.
*/

View File

@ -1,48 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Events observer for core_search purposes.
*
* @package core_search
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Event observer for search.
*
* @package core_search
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_search_observer {
/**
* Invalidates search results cache.
*
* Quite aggressive as search_results cache is per session.
*
* @param \core\event\search_indexed $event
* @return void
*/
public static function invalidate_caches(\core\event\search_indexed $event) {
$cache = \cache::make('core', 'search_results');
$cache->purge();
}
}

View File

@ -199,7 +199,6 @@ class search_solr_engine_testcase extends advanced_testcase {
$areaid = \core_search\manager::generate_areaid('core_mocksearch', 'role_capabilities');
$this->search->delete_index($areaid);
cache_helper::purge_by_definition('core', 'search_results');
$this->assertCount(0, $this->search->search($querydata));
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2016033100.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2016033100.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.