Skip to content

Conversation

fiblan
Copy link

@fiblan fiblan commented Oct 8, 2025

Problem

The function mod_videotime_view_videotime in mod_videotime is registered as type 'write' in db/services.php, which means Moodle keeps the user session open during execution. This can cause session locking issues during periods of heavy load, potentially blocking the session and negatively impacting user experience and performance.

Technical Details

'mod_videotime_view_videotime' => [
    'type' => 'write',
    'ajax' => true,
    // ...
]

The implementation in classes/external/view_videotime.php does not close the session after permission checks, so the session remains locked for the entire request duration:

public static function view_videotime($cmid) {
    // ...
    require_login($course, false, $cm);
    require_capability('mod/videotime:view', $context);
    // Session remains open here
    $moduleinstance = videotime_instance::instance_by_id($cm->instance);
    videotime_view($moduleinstance, $course, $cm, $context);
    return null;
}

Suggested Fix

To avoid session locking issues, close the session after authentication and capability checks:

require_login($course, false, $cm);
require_capability('mod/videotime:view', $context);
\core\session\manager::write_close(); // Add this line to release session lock

Benefit

This change will:

  • Reduce risk of performance bottlenecks on high-traffic sites

References

Discussion: Session unlocking

Reduce risk of performance bottlenecks on high-traffic sites
@fiblan
Copy link
Author

fiblan commented Oct 8, 2025

By unlocking the session, could there be situations that might create inconsistencies?

@fiblan
Copy link
Author

fiblan commented Oct 14, 2025

Can you restart checks? i removed unecessary blank line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant