DEV Community

Discussion on: What was your win this week?

 
ben profile image
Ben Halpern

If I understand correctly — why do we do this later and not right on save?

Basically we need to inspect the files for their meta data. We use FastImage because it's fast, but it is still a remote transaction and we'd rather not add extra latency in case the process hangs for any reason.

Thread Thread
 
grahamthedev profile image
GrahamTheDev

Ah that makes sense so saving doesn’t get held up!

But then you cache the value afterwards so you only have to look up the meta data once (well twice from what I gather from the PR! 🤣) and then update the HTML with the width and height values?

Very smart!

Thread Thread
 
ben profile image
Ben Halpern

Yeah, we store HTML in the DB, so only ever re-compute on changes. (This approach could change slightly over time to give us more flexibility, but it works well for efficiency).

And yeah — FastImage seems to allow you to look up either size, type, or animated, but doesn't let you open up the image to look for everything at once. 🤷‍♂️

Thread Thread
 
grahamthedev profile image
GrahamTheDev

Thought I had replied, must have closed browser by mistake 🙄

Looks like you are right, Line 223 in fastimages

 @property = if @options[:animated_only]
      :animated
    elsif @options[:type_only]
      :type
    else
      :size
    end
Enter fullscreen mode Exit fullscreen mode

So it looks to be animated, type or size as you thought.

Pretty sure you could extend it and just call them both together but that is probably an over optimisation!

Great solution for CLS either way ! ❤

Thread Thread
 
ben profile image
Ben Halpern

I’d consider this an over optimization for the matter of this first PR, but once it’s merged, a dedicated task to optimize this makes sense.