PlaidWeb / Publ

Flexible publishing system for the web
http://publ.beesbuzz.biz/
MIT License
40 stars 4 forks source link

Only render images on first retrieval #455

Closed fluffy-critter closed 2 years ago

fluffy-critter commented 2 years ago

Expected Behavior

Make the _async handler trigger the rendition of an unrendered image, instead of LocalImage._get_rendition.

Current Behavior

Preemptive rendering of images is pretty wasteful for things like e.g. opengraph cards which are only rarely accessed.

Possible Solution

Async image URLs should have the render parameters and a signing token, rather than the final rendered image path.

The request should still just fire off the render request and block for a short random amount of time before redirecting to the final URL (so as to not block page render threads/workers), and a timeout should still result in the colorblob (or, eventually, a blurhash as described in #241).

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

Literally every image on my site stays fresh in the rendition cache. There is no need for about 90% of those 3GB of image files to stick around.

fluffy-critter commented 2 years ago

Considered: Instead of dealing with signed URLs, maybe the path itself could be associated with a job that gets submitted. That seems like a potential garbage collection nightmare, though, and those jobs would eventually have to be expired somehow. So, better to just use a signed URL.

fluffy-critter commented 2 years ago

Solution: When a rendition is requested, if the rendition file exists, return that; otherwise, return a URL encoded using itsdangerous.URLSafeSerializer that encodes the rendition parameters as a tuple of (asset_path,kwargs). Then the _async handler can deserialize the URL and run the normal render process that way.