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

static cache in core_filetypes::get_types improvement

XMLWordPrintable

      Static caching in core_filetypes::get_types does not fully work because the cache is set at the end:

              self::$cachedtypes = $mimetypes;
              return self::$cachedtypes;
      

      but if there are no custom types, the fragment above is never reached because of:

              // If there are no custom types, just return.
              $custom = self::get_custom_types();
              if (empty($custom)) {
                  return $mimetypes;
              }
      

      Very simple fix is:

             // If there are no custom types, just return.
              $custom = self::get_custom_types();
              if (empty($custom)) {
                  self::$cachedtypes = $mimetypes;
                  return self::$cachedtypes;
              }
      

      Profiling run with a course with a lot of resources, before the fix:
      get_mimetypes_array 7,617 0.3% 1,520,192 12.9% 20,065

      and after the fix:
      get_mimetypes_array 7,617 0.3% 24,501 0.3% 16,603

        1. after.png
          29 kB
          Tomasz Muras
        2. before.png
          31 kB
          Tomasz Muras

            tmuras Tomasz Muras
            tmuras Tomasz Muras
            Jan Dageförde Jan Dageförde
            Andrew Lyons Andrew Lyons
            CiBoT CiBoT
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

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