From b31a22d4a102fb01a9f4657751aaf413912a59c1 Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Thu, 20 May 2021 20:52:19 -0700 Subject: [PATCH] Start serving outfit images via Impress 2020 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As part of our project to get off S3 and dramatically reduce costs, we're gonna start serving outfit images that Impress 2020 generates, fronted by Vercel's CDN cache! This should hopefully be just as fast in practice, without requiring an S3 storage cost. (Outfits whose thumbnails are pretty much unused will be evicted from the cache, or never stored in the first place—and regenerated back into the cache on-demand if needed.) One important note is that the image at the URL will no longer be guaranteed to auto-update to reflect the changes to the outfit, because we're including `updated_at` in the URL for caching. (It also isn't guaranteed to _not_ auto-update, though 😅) Our hope is that people aren't using it for that use case so much! If so, though, we have some ways we could build live URLs without putting too much pressure on image generation, e.g. redirects 🤔 This change does _not_ disable actual outfit generation, because I want to keep that running until we see these new URLs succeed for folks. Gonna wait a bit and see if we get bug reports on them! Then, if all goes well, we'll stop enqueueing outfit image jobs altogether, and maybe wind down some of the infrastructure accordingly. --- app/models/outfit.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/models/outfit.rb b/app/models/outfit.rb index 13bb3304..b1323d52 100644 --- a/app/models/outfit.rb +++ b/app/models/outfit.rb @@ -27,10 +27,25 @@ class Outfit < ActiveRecord::Base end def image_versions - {}.tap do |versions| - versions[:large] = image.url - image.versions.each { |name, version| versions[name] = version.url } - end + # Now, instead of using the saved outfit to S3, we're trying out the + # DTI 2020 API + CDN cache version. + # + # TODO: We're still saving outfit images for now, but we'll stop + # doing that if this transition goes well! + base_url = "https://impress-2020.openneo.net/outfits" + + "/#{CGI.escape id.to_s}" + + "/v/#{CGI.escape updated_at.to_i.to_s}" + { + large: "#{base_url}/600.png", + medium: "#{base_url}/300.png", + small: "#{base_url}/150.png", + } + + # NOTE: Below is the previous code that uses the saved outfits! + # {}.tap do |versions| + # versions[:large] = image.url + # image.versions.each { |name, version| versions[name] = version.url } + # end end def closet_item_ids