Use media availability instead of querying the filesystem #6428
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.
This change allows us to query the database instead of the file system or remote storage to get whether a version has a download of a specific type.
Currently, we rely on the presence of a file existing at a certain filesystem or storage path to determine whether media/downloads are available. As we move toward storage being an abstraction on top of the filesystem where it is possibly remote (eg. Cloud storage) we don't want to have to query remote storage to know whether a version has a PDF.
Instead, we started caching whether a version has builds of a specific type (eg. a PDF, ePub) and storing it on the
Version
model. After we started storing that data, a script was run to store the results for all previously built versions.This builds on work in #6278
Future work
There's some additional work I didn't add into this PR to keep it minimal. However, we could add this cleanup if desired:
Project.get_downloads
method which gets project downloads for the default version. As far as I can tell, this is not used.Project.has_pdf
,Project.has_epub
, andProject.has_htmlzip
methods. These do not appear to be used anymore. Alternatively, these could be changed to get the version object and query it instead of hitting the filesystem/storage. I think it really depends on whether we want to maintain this API.