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

Web service: Token last access is updated too frequently

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. Set up your Moodle environment to allow the mobile app.
      2. Connect to the mobile app using a test account (note the user id of the test user). For simplicity, use a test account that doersn't have any other web service tokens.
      3. Run this database query, using your prefix and replacing 12345 with your user id: SELECT lastaccess FROM mdl_external_tokens WHERE userid=12345
      4. Check the lastaccess time e.g. using www.epochconverter.com. It should show roughly the current time, when you connected to the mobile app.
      5. Wait at least 1 minute since that time, then do something in the mobile app that will cause it to request data from the server - e.g. view a course you have not viewed recently.
      6. Repeat the database query above and confirm the lastaccess changed to current time. Keep a record of this time.
      7. Within less than 1 minute (e.g. 30 seconds) of this time, do something else in the mobile app that will cause it to request data.
      8. Repeat the database query and confirm that this time, the lastaccess did not change. (Because it only updates when it is at least 1 minute newer.)
      Show
      Set up your Moodle environment to allow the mobile app. Connect to the mobile app using a test account (note the user id of the test user). For simplicity, use a test account that doersn't have any other web service tokens. Run this database query, using your prefix and replacing 12345 with your user id: SELECT lastaccess FROM mdl_external_tokens WHERE userid=12345 Check the lastaccess time e.g. using www.epochconverter.com. It should show roughly the current time, when you connected to the mobile app. Wait at least 1 minute since that time, then do something in the mobile app that will cause it to request data from the server - e.g. view a course you have not viewed recently. Repeat the database query above and confirm the lastaccess changed to current time. Keep a record of this time. Within less than 1 minute (e.g. 30 seconds) of this time, do something else in the mobile app that will cause it to request data. Repeat the database query and confirm that this time, the lastaccess did not change. (Because it only updates when it is at least 1 minute newer.)
    • Affected Branches:
      MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE
    • Fixed Branches:
      MOODLE_35_STABLE, MOODLE_36_STABLE
    • Pull 3.5 Branch:
      MDL-65179-m35
    • Pull 3.6 Branch:
      MDL-65179-m36
    • Pull Master Branch:
      MDL-65179-master

      Description

      The 'last access' time on external tokens is updated every time that a token is used. This was probably OK when web services were first implemented but is not so good when using the mobile app.

      For example, when a user connects with the mobile app, it may make ~20 web service requests within a few seconds, many of them simultaneously. This will cause the external_tokens table to be updated 20 times. In some of those cases it may be the same second so the update won't even change anything.

      This is a slight performance problem because databases have to do a lot of work each time the table is updated.

      I propose changing so that it only updates once per minute, which will reduce the number of database writes significantly. In the case of logging into the web app, this would mean the table gets updated 1 time instead of 20 times. There may also be slight improvements while continuing to use the mobile app.

      There is already code that does the same thing for the user_lastaccess table, via the LASTACCESS_UPDATE_SECS global define (also set to 60) so this is analagous.

        Attachments

          Activity

            People

            • Assignee:
              quen Sam Marshall
              Reporter:
              quen Sam Marshall
              Peer reviewer:
              Tim Hunt
              Integrator:
              Eloy Lafuente (stronk7)
              Tester:
              Eloy Lafuente (stronk7)
              Participants:
              Component watchers:
              Matteo Scaramuccia, Jake Dallimore, Jun Pataleta, Ryan Wyllie, Juan Leyva, Jake Dallimore, Jun Pataleta, Ryan Wyllie
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                13/May/19

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 10 minutes
                1h 10m