openfun / joanie

👛 A headless ERP for education to manage course enrollment/subscription, payment and certificates delivery.
MIT License
22 stars 2 forks source link

✨(backend) add images field to Certificate models #773

Closed jbpenrath closed 5 months ago

jbpenrath commented 5 months ago

Purpose

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 :

  1. 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.

  2. 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.

  3. 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