Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-77321

Report definition is cached and it does not work well with sending scheduled reports


    • WP Sprint 2023-I1.2 (Paul)

      We hit this problem on Workplace but I think I can find examples in LMS as well.

      There are some rare cases when the report definition depends on the current user. In case of Workplace, we add a tenant subquery to the "User list" datasource, for example so the same report for different users has different SQL and produces different results.

      When we create a schedule for such report, the datasource definition is created for the first user in the batch and then re-used for all other users, even if the schedule setting is to generate a new report for each user.

      As a very simple solution I can suggest to add a user id in the cache key. I'll try to come up with some testing instructions or unittests for this in LMS.

      diff --git a/reportbuilder/classes/manager.php b/reportbuilder/classes/manager.php
      index 143a7cd20ef..cebfa5b775d 100644
      --- a/reportbuilder/classes/manager.php
      +++ b/reportbuilder/classes/manager.php
      @@ -50,7 +50,8 @@ class manager {
            * @throws source_unavailable_exception
           public static function get_report_from_persistent(report $report, array $parameters = []): base {
      -        $instancekey = $report->get('id');
      +        global $USER;
      +        $instancekey = $report->get('id') . ':' . $USER->id;
               if (!array_key_exists($instancekey, static::$instances)) {
                   $source = $report->get('source');

            pholden Paul Holden
            marina Marina Glancy
            Odei Alba Odei Alba
            David Carrillo David Carrillo
            CiBoT CiBoT
            1 Vote for this issue
            5 Start watching this issue


                Original Estimate - Not Specified
                Not Specified
                Remaining Estimate - 0 minutes
                Time Spent - 2 hours, 15 minutes
                2h 15m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.