Currently, to generate Contract and Certificate we are using a context which is stored in JSONField. This is convenient but currently, it does not scale well (in term of database space volumetry) as we are embedding into those contexts images encoded in base64... (In production, the average size of a certificate context is ~40Ko).
We have identified three ways to improve things :
Stop to store base64 images in context
Instead we could store images into a classic ImageField then embedded in the context the id of the resource.
Prevent image duplication on media storage
If we start to store images on media storage, we could prevent to duplicate images for each documents. We could prevent that by calculate a checksum and store it in database then at the moment to create the asset, we could check if one with the checksum already exist and reuse it if necessary.
Compress images on save
In order to optimize space consumption, we could also compress images. IMO, this step is not mandatory compare to two previous steps and as Contract and Certificate should be printable, image quality must be good enough for that purpose.
Proposal
[x] Create a generic model DocumentImage which aims to store all files used in "Document" model (currently Contract & Certificate).
[x] Declare a unique checksum field on DocumentImage model to prevent to store twice the same image.
[x] First update Certificate context generation logic
Purpose
Currently, to generate
Contract
andCertificate
we are using a context which is stored in JSONField. This is convenient but currently, it does not scale well (in term of database space volumetry) as we are embedding into those contexts images encoded in base64... (In production, the average size of a certificate context is ~40Ko).We have identified three ways to improve things :
Stop to store base64 images in context Instead we could store images into a classic
ImageField
then embedded in the context the id of the resource.Prevent image duplication on media storage If we start to store images on media storage, we could prevent to duplicate images for each documents. We could prevent that by calculate a checksum and store it in database then at the moment to create the asset, we could check if one with the checksum already exist and reuse it if necessary.
Compress images on save In order to optimize space consumption, we could also compress images. IMO, this step is not mandatory compare to two previous steps and as Contract and Certificate should be printable, image quality must be good enough for that purpose.
Proposal
DocumentImage
which aims to store all files used in "Document" model (currentlyContract
&Certificate
).checksum
field onDocumentImage
model to prevent to store twice the same image.