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

improvement to context_rel table and load_user_capability()

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.3, 1.9
    • Fix Version/s: 1.9
    • Component/s: Roles / Access
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      The context_rel table is a caching table built to allow the big SQL in load_user_capability() to be able to identify the pair of contexts that are related easily, (e.g. parent/child or grandparent/child), where you have an override at a lower context level, and an assignment at the higher context level.

      The current issue we have is that the number of entries in context_rel table is normally a few times larger than the context table. Working with such a large table takes quite a bit of space and can potentially cause load_user_capability() to run slower.

      However, there is no point (IMHO) to store the pair of contexts in the context_rel table if
      1) There is no role assignment at the higher context OR
      2) There is no role override in the lower context

      Currently the context_rel table is populated whenever a new context is inserted. Given that the number of contexts with any overrides is much less than the number of contexts in which we have a direct role assignment, I propose we make the following changes

      1) Do not populate the context_rel table upon context creation.
      2) Populate the context_rel table whenever an override is added.
      3) Take out entries from context_rel if the last override is removed.
      4) build_context_rel() should loop all context and only populate contexts with overrides when users upgrades. (current, for users from 1.7 and below)
      5) In 1.9, drop the context_rel table and call build_context_rel().

        Attachments

          Activity

            People

            • Assignee:
              lazyfish Yu Zhang
              Reporter:
              lazyfish Yu Zhang
              Participants:
              Component watchers:
              Amaia Anabitarte, Bas Brands, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                3/Mar/08