Compare commits

...

2 commits

Author SHA1 Message Date
bec350e9f2 Filter trade lists to active users only
I don't have the cute fancy UI with trade list names included, but! Now
the trade ratios should match DTI 2020 and that's nice!
2024-01-19 00:38:16 -08:00
16328d3840 Refactor how we load closet hangers
Ahh I see, the way we got away with not having a `trading` scope before
was a weird metaprogramming `{owned/wanted}_trading` situation. Okay,
let's trash that in favor of our new stuff! And that helps us bulk the
queries too which is nice.
2024-01-19 00:28:28 -08:00
2 changed files with 13 additions and 16 deletions

View file

@ -71,9 +71,12 @@ class ItemsController < ApplicationController
@basic_colored_pet_types_by_species_id = PetType.special_color_or_basic(@item.special_color). @basic_colored_pet_types_by_species_id = PetType.special_color_or_basic(@item.special_color).
includes_child_translations.group_by(&:species) includes_child_translations.group_by(&:species)
trading_closet_hangers = @item.closet_hangers.trading.newest.
user_is_active.includes(:user)
@trading_closet_hangers_by_owned = { @trading_closet_hangers_by_owned = {
true => @item.closet_hangers.owned_trading.newest.includes(:user), true => trading_closet_hangers.filter { |c| c.owned? },
false => @item.closet_hangers.wanted_trading.newest.includes(:user) false => trading_closet_hangers.filter { |c| c.wanted? },
} }
if user_signed_in? if user_signed_in?

View file

@ -46,20 +46,10 @@ class ClosetHanger < ApplicationRecord
scope :newest, -> { order(arel_table[:created_at].desc) } scope :newest, -> { order(arel_table[:created_at].desc) }
scope :owned_before_wanted, -> { order(arel_table[:owned].desc) } scope :owned_before_wanted, -> { order(arel_table[:owned].desc) }
scope :unlisted, -> { where(:list_id => nil) } scope :unlisted, -> { where(:list_id => nil) }
scope :user_is_active, -> {
{:owned => true, :wanted => false}.each do |name, owned| u = User.arel_table
scope "#{name}_trading", -> { joins(:user).where(u[:last_trade_activity_at].gteq(6.months.ago))
joins(:user).includes(:list). }
where(:owned => owned).
where((
arel_table[:list_id].eq(nil).and(
User.arel_table["#{name}_closet_hangers_visibility"].gteq(ClosetVisibility[:trading].id)
)
).or(
ClosetList.arel_table[:visibility].gteq(ClosetVisibility[:trading].id)
))
}
end
before_validation :merge_quantities, :set_owned_by_list before_validation :merge_quantities, :set_owned_by_list
@ -74,6 +64,10 @@ class ClosetHanger < ApplicationRecord
possibly_null_closet_list.trading? possibly_null_closet_list.trading?
end end
def wanted?
!owned?
end
def possibly_null_list_id=(list_id_or_owned) def possibly_null_list_id=(list_id_or_owned)
if list_id_or_owned.to_s == 'true' || list_id_or_owned.to_s == 'false' if list_id_or_owned.to_s == 'true' || list_id_or_owned.to_s == 'false'
self.list_id = nil self.list_id = nil