simonw / til

Today I Learned
https://til.simonwillison.net
Apache License 2.0
1.02k stars 81 forks source link

Avoid retaking all screenshots on publish unless strictly necessary #82

Closed simonw closed 10 months ago

simonw commented 10 months ago

Deploy will take half an hour because it's going to need to rebuild all 450 screenshots due to an (invisible) change to the entry HTML.

Originally posted by @simonw in https://github.com/simonw/til/issues/81#issuecomment-1685012429

simonw commented 10 months ago

Changes to the content of a TIL should generate a new screenshot of that TIL.

But, right now, even the tiniest tweak to the base or entry templates (including changes that wouldn't visibly affect the shots at all) triggers a 450+ screenshot generation process.

simonw commented 10 months ago

Easiest fix: instead of incorporating the hash of the HTML templates themselves, switch to a SCREENSHOT_VERSION constant. I can then manually change that any time I want to trigger a full re-render.

simonw commented 10 months ago

I could set the first version of that to the current hash, to avoid recalculating all 450 existing shots when I deploy this change.

simonw commented 10 months ago

https://github.com/simonw/til/blob/b8ab160caf7201b4f4738c1eba4c15d3fcafd97c/generate_screenshots.py#L10-L13

https://github.com/simonw/til/blob/b8ab160caf7201b4f4738c1eba4c15d3fcafd97c/generate_screenshots.py#L57-L60

Since those hashes are added in sequence, the constant would need to be a list in order to capture the current state.

simonw commented 10 months ago

If I got this right, the deploy should not recreate any screenshots.

simonw commented 10 months ago

Yes that worked:

CleanShot 2023-08-19 at 09 18 03@2x