catalyst / moodle-mod_reengagement

Allows timed release of content and emails users to remind them to complete a course activity
23 stars 39 forks source link

Ad-hoc Task Implementation for Performance Improvement in Course Modules #160

Closed rajandangi closed 2 months ago

rajandangi commented 2 months ago

In this PR, I have made the following changes to optimize performance:

  1. Changed the method of retrieving re-engagement module instances using PHP generators to minimize memory usage. View Code
  2. Created individual ad-hoc tasks for each course module.
  3. Previously, all users of each course module were fetched, and their availability was checked, causing significant slowdowns. To address this, I introduced an offset and batch size mechanism for each course module. Now, it processes users in batches of 1000. For subsequent runs, it processes the next set of 1000 users, continuing until all users are processed. If a course module has fewer than or equal to 1000 users, they will be processed in one run; for larger user sets, the task will complete in multiple runs. This ensures each course module is processed independently without affecting others. View Code

The overall processing time for the scheduled and ad-hoc tasks is significantly reduced with these changes. Consequently, it is now feasible to run scheduled and ad-hoc tasks multiple times a day instead of running a single lengthy task. This approach reduces memory usage, enhances execution time, and minimizes potential timeout issues associated with longer tasks.