From e846a75f7a138bfa7812542a8d0d006af92b9ef0 Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Wed, 20 Nov 2024 11:22:33 -0800 Subject: [PATCH] Use modeling hints to remove some items from `is:modeling` searches There's still plenty left, but we have 213 we "manually" marked as "done" (I think I ran a batch job on everything Chips told me was on the page and already done), and that should help a lot! --- app/models/item.rb | 13 ++++++++++++- spec/models/item_spec.rb | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/models/item.rb b/app/models/item.rb index a65a9352..cb921400 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -31,6 +31,9 @@ class Item < ApplicationRecord validates :description, :thumbnail_url, :rarity, :price, :zones_restrict, exclusion: {in: [nil], message: "must be specified"} + after_save :update_cached_fields, + if: :modeling_status_hint_previously_changed? + attr_writer :current_body_id, :owned, :wanted NCRarities = [0, 500] @@ -300,8 +303,16 @@ class Item < ApplicationRecord write_attribute('species_support_ids', replacement) end + def modeling_hinted_done? + modeling_status_hint == "done" || modeling_status_hint == "glitchy" + end + def predicted_body_ids - @predicted_body_ids ||= if compatible_body_ids.include?(0) + @predicted_body_ids ||= if modeling_hinted_done? + # If we've manually set this item to no longer report as needing modeling, + # predict that the current bodies are all of the compatible bodies. + compatible_body_ids + elsif compatible_body_ids.include?(0) # Oh, look, it's already known to fit everybody! Sweet. We're done. (This # isn't folded into the case below, in case this item somehow got a # body-specific and non-body-specific asset. In all the cases I've seen diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index bc8e0b47..5ae5cc9c 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -231,5 +231,46 @@ RSpec.describe Item do expect(item.compatible_body_ids).to contain_exactly(1, 2, 3, 4) end end + + describe "an item without any modeling data, but hinted as done" do + subject(:item) { items(:birthday_bg) } + + before { item.update!(modeling_status_hint: :done) } + + it_behaves_like "a fully-modeled item" + it("has no compatible body IDs") do + expect(item.compatible_body_ids).to be_empty + end + end + + describe "an item with two species modeled, but hinted as done" do + subject(:item) { items(:birthday_bg) } + + before do + item.swf_assets << build_item_asset(zones(:wings), body_id: 1) + item.swf_assets << build_item_asset(zones(:wings), body_id: 2) + item.update!(modeling_status_hint: :done) + end + + it_behaves_like "a fully-modeled item" + it("has two compatible body IDs") do + expect(item.compatible_body_ids).to contain_exactly(1, 2) + end + end + + describe "an item with two species modeled, but hinted as glitchy" do + subject(:item) { items(:birthday_bg) } + + before do + item.swf_assets << build_item_asset(zones(:wings), body_id: 1) + item.swf_assets << build_item_asset(zones(:wings), body_id: 2) + item.update!(modeling_status_hint: :glitchy) + end + + it_behaves_like "a fully-modeled item" + it("has two compatible body IDs") do + expect(item.compatible_body_ids).to contain_exactly(1, 2) + end + end end end