MDL-77321 reportbuilder: cache list of loaded reports per user.

Since 0188af39 we've cached loaded reports, however there was an
edge case in those report sources that relied on the current user
as part of their own initialization (e.g. checking capabilities).

Co-authored-by: Marina Glancy <[email protected]>
This commit is contained in:
Paul Holden
2023-02-27 21:13:11 +00:00
co-authored by Marina Glancy
parent 9ee4f8db8b
commit 54b135e034
2 changed files with 51 additions and 4 deletions
+6 -2
View File
@@ -40,7 +40,7 @@ class manager {
/**
* Return an instance of a report class from the given report persistent
*
* We statically cache the list of loaded reports during request lifecycle, to allow this method to be called
* We statically cache the list of loaded reports per user during request lifecycle, to allow this method to be called
* repeatedly without potential performance problems initialising the same report multiple times
*
* @param report $report
@@ -50,7 +50,11 @@ class manager {
* @throws source_unavailable_exception
*/
public static function get_report_from_persistent(report $report, array $parameters = []): base {
$instancekey = $report->get('id');
global $USER;
// Cached instance per report/user, to account for initialization dependent on current user.
$instancekey = $report->get('id') . ':' . ($USER->id ?? 0);
if (!array_key_exists($instancekey, static::$instances)) {
$source = $report->get('source');