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

static cache in core_filetypes::get_types improvement

    XMLWordPrintable

    Details

      Description

      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

        Attachments

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

          Activity

            People

            Assignee:
            tmuras Tomasz Muras
            Reporter:
            tmuras Tomasz Muras
            Peer reviewer:
            Jan Dageförde
            Integrator:
            Andrew Nicols
            Tester:
            CiBoT
            Participants:
            Component watchers:
            Matteo Scaramuccia, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              14/Jan/19