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

Change the question_attempt class to only call apply_attempt_state if necessary

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • 3.9
    • 3.5.8, 3.6.6, 3.7.2, 3.7.5, 3.8.2
    • Performance, Questions
    • MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE
    • MOODLE_39_STABLE
    • Hide

      Testing this is most easy if you are able to edit the Moodle code. you should have developer debug on for this.

      Set up

      1. Create a quiz.
      2. Add three multiple-choice questions, each on a separate page.
      3. Make sure there is a student enroled in the course.

      Hack code

      Edit question\type\multichoice\question.php, and at the top of the function apply_attempt_state, insert these two lines.

              debugging("In apply_attempt_state");
      

      This means that you will get debug info on screen every time a question is initialised.

      Test

      1. Log in as student.
      2. Go to the quiz.
      3. Verify that there are no 'In apply_attempt_state' messages.
      4. Click 'Start attempt'.
      5. Verify that you do not get stopped on the page with URL startattempt.php.
      6. Verify that on the first page of the quiz (attempt.php) there is a single 'In apply_attempt_state' message.
      7. Answer the question, and click 'Next'.
      8. Verify that it stops on processattempt.php with a single 'In apply_attempt_state' message, and the message 'Error output, so disabling automatic redirect.'
      9. Click 'Continue'.
      10. Verify that you are on page 2 of the quiz with a single 'In apply_attempt_state' message.
      11. Click 'Finsh attempt...'.
      12. Verify that you are on processattempt.php with one 'In apply_attempt_state' message.
      13. Click contine.
      14. Verify that you are on the quiz summary page (summary.php) with no 'In apply_attempt_state' messages.
      15. Do 'Submit all and finish'.
      16. Verify that it stops on processattempt.php with three 'In apply_attempt_state' messages
      17. Click 'Continue'.
      18. Verify that you are on the attempt review page (review.php) with three 'In apply_attempt_state' messages (cause the review shows all questions on one page.
      19. Click 'Finish review'.
      20. Verify that you are on the quiz info page (view.php) with no 'In apply_attempt_state' messages.

      Don't forget to undo the edit in question\type\multichoice\question.php once you have finished.

      In addition to this manual test, the unit test and Behat tests will provide a pretty thorough regression test.

      Show
      Testing this is most easy if you are able to edit the Moodle code. you should have developer debug on for this. Set up Create a quiz. Add three multiple-choice questions, each on a separate page. Make sure there is a student enroled in the course. Hack code Edit question\type\multichoice\question.php, and at the top of the function apply_attempt_state, insert these two lines. debugging( "In apply_attempt_state" ); This means that you will get debug info on screen every time a question is initialised. Test Log in as student. Go to the quiz. Verify that there are no 'In apply_attempt_state' messages. Click 'Start attempt'. Verify that you do not get stopped on the page with URL startattempt.php. Verify that on the first page of the quiz (attempt.php) there is a single 'In apply_attempt_state' message. Answer the question, and click 'Next'. Verify that it stops on processattempt.php with a single 'In apply_attempt_state' message, and the message 'Error output, so disabling automatic redirect.' Click 'Continue'. Verify that you are on page 2 of the quiz with a single 'In apply_attempt_state' message. Click 'Finsh attempt...'. Verify that you are on processattempt.php with one 'In apply_attempt_state' message. Click contine. Verify that you are on the quiz summary page (summary.php) with no 'In apply_attempt_state' messages. Do 'Submit all and finish'. Verify that it stops on processattempt.php with three 'In apply_attempt_state' messages Click 'Continue'. Verify that you are on the attempt review page (review.php) with three 'In apply_attempt_state' messages (cause the review shows all questions on one page. Click 'Finish review'. Verify that you are on the quiz info page (view.php) with no 'In apply_attempt_state' messages. Don't forget to undo the edit in question\type\multichoice\question.php once you have finished. In addition to this manual test, the unit test and Behat tests will provide a pretty thorough regression test.

      At the moment, when a question_usage is loaded from the database, the question used by each question_attempt is fully initialised by calling $question->apply_attempt_state($qa->steps[0]). https://github.com/moodle/moodle/blob/01aa126848377b5a17c0b57f3b81d1ab430dad86/question/engine/questionattempt.php#L1557

      When using sophisticated question types like STACK, apply_attempt_state is necessarily quite expensive.

      It might be possible to change this to a lazy-load (or rather a lazy-init), so that rather calling apply_attempt_state on-load, we call it the first time a method of question_attempt that needs the question to be initialised is called. This could be a relatively painless performance win.

      See https://moodle.org/mod/forum/discuss.php?d=393058#p1585280 for the thread that lead to this idea.

        1. MDL-67183-step8.png
          MDL-67183-step8.png
          111 kB
        2. MDL-67183-step6.png
          MDL-67183-step6.png
          96 kB
        3. MDL-67183-step3.png
          MDL-67183-step3.png
          51 kB
        4. MDL-67183-step20.png
          MDL-67183-step20.png
          113 kB
        5. MDL-67183-step18.png
          MDL-67183-step18.png
          185 kB
        6. MDL-67183-step16.png
          MDL-67183-step16.png
          190 kB
        7. MDL-67183-step14.png
          MDL-67183-step14.png
          100 kB
        8. MDL-67183-step12.png
          MDL-67183-step12.png
          110 kB
        9. MDL-67183-step10.png
          MDL-67183-step10.png
          94 kB

            timhunt Tim Hunt
            timhunt Tim Hunt
            Neill Magill Neill Magill
            Victor Déniz Falcón Victor Déniz Falcón
            Michael Hawkins Michael Hawkins
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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