Compare commits

...

5 commits

Author SHA1 Message Date
1e99376449 Remove hundreds of unnecessary queries from /alt-styles page!
I think the Rails query cache handled these anyway? But `SwfAsset` has
a `before_save` hook that checks its zone's info, and
`SwfAsset.preload_manifests` saves all the assets, on the assumption
that saving is a no-op when the record didn't change anyway. And it
basically is!

But I figure that, now that I'm realizing hooks exist, simply not
attempting to save unchanged records is probably a better
representation of what we intend to do. So I'm fixing it like that!

Another potential fix would be to preload the zones for these assets,
but I think that confuses the intent too much; the method itself isn't
using the zones, it's just a weird incidental thing that a save hook
happens to use. (Would probably be better to refactor this old save
hook into a different situation altogether, but that's for another
time!)
2024-05-29 18:52:36 -07:00
244bb7627a Remove outdated info from Alt Styles page
Apparently I correctly updated the first paragraph, but not the third
one, oops lol!
2024-05-29 18:47:06 -07:00
285cf233f0 Assume new alt styles are "Nostalgic" until the end of 2024 2024-05-29 18:46:17 -07:00
b06e8a25c0 Validate presence of body ID when saving AltStyle
This is a minor nbd change, I just noticed when playing around in the
console that, unlike most other errors for this model, the `body_id`
being required is _only_ enforced in the database schema, so it isn't
returned with the usual errors. Not a big deal! Just feels like this is
clearer to work with, and more correct to what we *intend*.
2024-05-29 18:42:41 -07:00
c78d51ab01 Don't hardcode the series name in AltStyle thumbnail_url
This is just a bit of future-proofing! We also add a default thumbnail
URL of the cute "Neopets Circle Background", for cases where the series
name isn't known yet.
2024-05-29 18:36:30 -07:00
3 changed files with 36 additions and 13 deletions

View file

@ -1,3 +1,5 @@
require "addressable/template"
class AltStyle < ApplicationRecord
belongs_to :species
belongs_to :color
@ -6,6 +8,10 @@ class AltStyle < ApplicationRecord
has_many :swf_assets, through: :parent_swf_asset_relationships
has_many :contributions, as: :contributed, inverse_of: :contributed
validates :body_id, presence: true
before_create :infer_series_name
scope :matching_name, ->(series_name, color_name, species_name) {
color = Color.find_by_name!(color_name)
species = Species.find_by_name!(species_name)
@ -35,11 +41,20 @@ class AltStyle < ApplicationRecord
"#{series_name} #{color.human_name}"
end
THUMBNAIL_URL_TEMPLATE = Addressable::Template.new(
"https://images.neopets.com/items/{series}_{color}_{species}.gif"
)
DEFAULT_THUMBNAIL_URL = "https://images.neopets.com/items/mall_bg_circle.gif"
def thumbnail_url
# HACK: Just assume this is a Nostalgic Alt Style, and that the thumbnail
# is named reliably!
"https://images.neopets.com/items/nostalgic_" +
"#{color.name.gsub(/\s+/, '').downcase}_#{species.name.downcase}.gif"
return DEFAULT_THUMBNAIL_URL unless has_real_series_name?
# HACK: We're assuming this is the format long-term! But if it changes, we
# may need to add it as a database field instead.
THUMBNAIL_URL_TEMPLATE.expand(
series: series_name.gsub(/\s+/, '').downcase,
color: color.name.gsub(/\s+/, '').downcase,
species: species.name.gsub(/\s+/, '').downcase,
).to_s
end
def preview_image_url
@ -63,6 +78,19 @@ class AltStyle < ApplicationRecord
end
end
# Until the end of 2024, assume new alt styles are from the "Nostalgic"
# series. That way, we can stop having to manually label them all as they
# come out and get modeled (TNT is prolific rn!), but we aren't gonna get too
# greedy and forget about this and use Nostalgic for some far-future thing,
# in ways that will certainly be fixable but would also be confusing and
# embarrassing.
NOSTALGIC_FINAL_DAY = Date.new(2024, 12, 31)
def infer_series_name
if !has_real_series_name? && Date.today <= NOSTALGIC_FINAL_DAY
self.series_name = "Nostalgic"
end
end
# For convenience in the console!
def self.find_by_name(color_name, species_name)
color = Color.find_by_name(color_name)

View file

@ -338,7 +338,7 @@ class SwfAsset < ApplicationRecord
end
SwfAsset.transaction do
swf_assets.each(&:save!)
swf_assets.select(&:changed?).each(&:save!)
end
end

View file

@ -9,14 +9,9 @@
name on the homepage! Thank you! 💖
%p
Also, heads-up: Style tokens are pretty different from normal wearables, so
we haven't decided how to bring them into the customizer yet! Whatever we do,
it'll be a bit tricky and new 😅❗️
%p
Also, second heads-up: Because our system can only collect "item data" for
normal wearable items, there's not a great way for us to get style tokens
onto tradelists… this may change someday, but probably not soon, sorry!
Also, heads-up: Because our system can only collect "item data" for normal
wearable items, there's not a great way for us to get style tokens onto
tradelists… this may change someday, but probably not soon, sorry!
- @alt_styles.group_by(&:species).each do |species, species_styles|
%h2.alt-styles-header= species.human_name