Cache course archives in the admin course archives directory. (hotfix of #3109) - #3110
Merged
Merged
Conversation
Anytime the `listArchivedCourses` method of the `WeBWorK::Utils::CourseManagement` package is called a cache of the course archive files in the admin course archives directory is created (if it does not exist) or updated (if new archive files are found, archive files are removed, or archive files are modified). Also, anytime a course archive is created and the archive file is stored in the archives directory of the admin course, the cache is updated. Note that when an archive file is added to the cache this way it is actually much faster than when it is added to the cache via the `listArchivedCourses` method since the tar archive does not need to be inspected at all (it was just created, so the course id is already known). Note that the `listArchivedCourses` approach for updating the cache for deleted archive files is really fast, so there is no need to handle that elsewhere. Unfortunately, if archive files are added or modified in other ways than creating a course archive via the `archiveCourse` method, there is no way to detect that. So the slow `listArchivedCourses` cache update is the only recourse. If there are only a few added archive files this is still relatively fast though. The archive cache is stored in the file `archives/archive-cache.json` in the admin course directory. The `listArchivedCourses` method is called when the "Course Listings" or "Unarchive Course" pages in the admin course are loaded. So if you have a lot of course archives in the admin course archives directory that are not yet cached, the load time will still be slow. However, once those archives are in the cache, the load time will be pretty much as fast as before. A `getHumanReadableFileSize` method was added to the `WeBWorK::Utils::Files` package since that is used both in the `listArchivedCourses` method and in the `archiveCourse` method, and might be useful elsewhere.
Alex-Jordan
approved these changes
Aug 5, 2026
Alex-Jordan
left a comment
Contributor
There was a problem hiding this comment.
This looks good. And it is working on my production server.
somiaj
approved these changes
Aug 5, 2026
somiaj
left a comment
Contributor
There was a problem hiding this comment.
Works and drastically speeds up viewing the course list page after the cache was built.
Should we add to the release notes that the first time logging into the admin course could take a bit while the cache is built?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Anytime the
listArchivedCoursesmethod of theWeBWorK::Utils::CourseManagementpackage is called a cache of the course archive files in the admin course archives directory is created (if it does not exist) or updated (if new archive files are found, archive files are removed, or archive files are modified).Also, anytime a course archive is created and the archive file is stored in the archives directory of the admin course, the cache is updated. Note that when an archive file is added to the cache this way it is actually much faster than when it is added to the cache via the
listArchivedCoursesmethod since the tar archive does not need to be inspected at all (it was just created, so the course id is already known).Note that the
listArchivedCoursesapproach for updating the cache for deleted archive files is really fast, so there is no need to handle that elsewhere. Unfortunately, if archive files are added or modified in other ways than creating a course archive via thearchiveCoursemethod, there is no way to detect that. So the slowlistArchivedCoursescache update is the only recourse. If there are only a few added archive files this is still relatively fast though.The archive cache is stored in the file
archives/archive-cache.jsonin the admin course directory.The
listArchivedCoursesmethod is called when the "Course Listings" or "Unarchive Course" pages in the admin course are loaded. So if you have a lot of course archives in the admin course archives directory that are not yet cached, the load time will still be slow. However, once those archives are in the cache, the load time will be pretty much as fast as before.A
getHumanReadableFileSizemethod was added to theWeBWorK::Utils::Filespackage since that is used both in thelistArchivedCoursesmethod and in thearchiveCoursemethod, and might be useful elsewhere.