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

Web service: Token last access is updated too frequently

XMLWordPrintable

    • MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE
    • MOODLE_35_STABLE, MOODLE_36_STABLE
    • MDL-65179-master
    • 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.)

      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.

            quen Sam Marshall
            quen Sam Marshall
            Tim Hunt Tim Hunt
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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