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:
Peter Spicer
2022-03-04 14:38:39 +10:00
committed by Peter Burnett
co-authored by Peter Burnett
parent 646c691107
commit 1c3084df01
5 changed files with 64 additions and 12 deletions
+15
View File
@@ -6185,6 +6185,21 @@ class context_helper extends context {
return $classname::get_level_name();
}
/**
* Gets the current context to be used for navigation tree filtering.
*
* @param context|null $context The current context to be checked against.
* @return context|null the context that navigation tree filtering should use.
*/
public static function get_navigation_filter_context(?context $context): ?context {
global $CFG;
if (!empty($CFG->filternavigationwithsystemcontext)) {
return context_system::instance();
} else {
return $context;
}
}
/**
* not used
*/