Skip to content

Cache course archives in the admin course archives directory. (hotfix of #3109) - #3110

Merged
somiaj merged 1 commit into
openwebwork:mainfrom
drgrice1:archived-course-cache-hotfix
Aug 5, 2026
Merged

Cache course archives in the admin course archives directory. (hotfix of #3109)#3110
somiaj merged 1 commit into
openwebwork:mainfrom
drgrice1:archived-course-cache-hotfix

Conversation

@drgrice1

@drgrice1 drgrice1 commented Aug 5, 2026

Copy link
Copy Markdown
Member

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.

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 Alex-Jordan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. And it is working on my production server.

@somiaj somiaj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@somiaj
somiaj merged commit 6e18508 into openwebwork:main Aug 5, 2026
2 checks passed
@drgrice1
drgrice1 deleted the archived-course-cache-hotfix branch August 6, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants