Skip to content

Commit

Permalink
MDL-53272 search: Remove search results cache
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Apr 4, 2016
1 parent 54abd66 commit 9470e4d
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 109 deletions.
1 change: 0 additions & 1 deletion lang/en/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
$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';
Expand Down
8 changes: 0 additions & 8 deletions lib/db/caches.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,6 @@
'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,
Expand Down
4 changes: 0 additions & 4 deletions lib/db/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
'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.
4 changes: 0 additions & 4 deletions report/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@

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();
}
}

Expand Down
42 changes: 0 additions & 42 deletions search/classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,6 @@ protected function get_areas_user_accesses() {
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();

Expand All @@ -424,40 +413,9 @@ public function search(\stdClass $formdata) {
$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.
*/
Expand Down
48 changes: 0 additions & 48 deletions search/classes/observer.php

This file was deleted.

1 change: 0 additions & 1 deletion search/engine/solr/tests/engine_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ public function test_delete() {

$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));
}

Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 9470e4d

Please sign in to comment.