MDL-67428 navigation: Apply navigation text filters at system context
On some larger sites, processing the navigation with format_string will habitually load all the contexts for navigation which can take 400+ DB queries. Explicitly tying all those format_string calls to the system context reduces this overhead to a single DB query that probably has already been run on the page previously. Co-authored-by: Peter Burnett <[email protected]>
This commit is contained in:
co-authored by
Peter Burnett
parent
646c691107
commit
1c3084df01
@@ -4595,6 +4595,29 @@ class core_accesslib_testcase extends advanced_testcase {
|
||||
$this->expectException(\required_capability_exception::class);
|
||||
require_all_capabilities($sca, $coursecontext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_navigation_filter_context.
|
||||
*
|
||||
* @covers ::get_navigation_filter_context
|
||||
*/
|
||||
public function test_get_navigation_filter_context() {
|
||||
$this->resetAfterTest();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
set_config('filternavigationwithsystemcontext', 0);
|
||||
// First test passed values are returned if disabled.
|
||||
$this->assertNull(context_helper::get_navigation_filter_context(null));
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
$filtercontext = context_helper::get_navigation_filter_context($coursecontext);
|
||||
$this->assertEquals($coursecontext->id, $filtercontext->id);
|
||||
|
||||
// Now test that any input returns system context if enabled.
|
||||
set_config('filternavigationwithsystemcontext', 1);
|
||||
$filtercontext = context_helper::get_navigation_filter_context(null);
|
||||
$this->assertInstanceOf('\context_system', $filtercontext);
|
||||
$filtercontext = context_helper::get_navigation_filter_context($coursecontext);
|
||||
$this->assertInstanceOf('\context_system', $filtercontext);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user