Skip to main content

Module storage

Module storage 

Source
Expand description

On-disk storage of saved render image bytes.

Saved renders are stored as files under <storage_dir>/renders/. Each file is named by the render’s UUID plus a suffix that distinguishes the primary image from the optional without-route variant. The DB row carries just the relative filename so the actual storage location can change without a schema migration.

Constants§

IMAGE_SUFFIX
Suffix used for the primary rendered image file.
IMAGE_WITHOUT_ROUTE_SUFFIX
Suffix used for the optional “without route” variant of a render.

Functions§

ensure_layout
Create the on-startup subdirectory layout under storage_dir.
ext_for_content_type
Map an image/... MIME type to the file extension that should be used on disk. Returns bin for anything unrecognised so the file is still preserved and can be inspected manually.
list_logo_files
List the filenames currently present under the logos/ subdirectory. Used by the orphan sweeper.
list_render_files
List the filenames currently present under the renders/ subdirectory. Used by the orphan sweeper.
logo_filename
Compute the relative filename (relative to <storage_dir>/logos/) for a logo’s image file given the logo id and extension.
logo_path
Compute the absolute path to a logo file.
parse_logo_id_from_filename
Extract the logo UUID prefix from a filename produced by logo_filename. Returns None if the filename does not start with a valid 36-character hyphenated UUID.
parse_render_id_from_filename
Extract the render UUID prefix from a filename produced by render_filename. Returns None if the filename does not start with a valid 36-character hyphenated UUID. Filenames are of the form {render_id}-{suffix}.{ext}, where render_id itself contains four hyphens, so we cannot just split on -.
read_logo_file
Read a logo’s image bytes back from disk.
read_render_file
Read the rendered image bytes back from disk.
render_filename
Compute the relative filename (relative to <storage_dir>/renders/) for a render’s image file given the render id, suffix, and extension.
render_path
Compute the absolute path to a render file.
try_delete_logo_file
Best-effort delete of a single logo file. A missing file is treated as success. See try_delete_render_file for the rationale.
try_delete_render_file
Best-effort delete of a single render file. A missing file is treated as success (the row may have been deleted already). Other errors are returned so the caller can decide whether to surface them or raise the sweeper “dirty” flag for a later retry.
write_logo_file
Write a logo’s image bytes to disk, returning the filename that should be stored in the DB.
write_render_file
Write the rendered image bytes for a render to disk, returning the filename that should be stored in the DB.