forked from OpenNeo/impress
Skip item translations when modeling
Okay, this is a process that idk if it's even been working for a while anyway, I don't think Neopets translates item names anymore? And it's crashing when I try to model stuff now, so like. yeah ok I'm fine with just skipping this, it's a shame to lose out on potential data going forward but *I think there just isn't data to get anyway*
This commit is contained in:
parent
5f3ce1210a
commit
d8b0bf3174
3 changed files with 1 additions and 66 deletions
|
@ -47,7 +47,6 @@ class PetsController < ApplicationController
|
|||
pet.save!
|
||||
points = true
|
||||
end
|
||||
pet.translate_items
|
||||
points
|
||||
end
|
||||
|
||||
|
|
|
@ -84,71 +84,6 @@ class Pet < ApplicationRecord
|
|||
end
|
||||
contributables
|
||||
end
|
||||
|
||||
def item_translation_candidates
|
||||
{}.tap do |candidates|
|
||||
if @items
|
||||
@items.each do |item|
|
||||
item.needed_translations.each do |locale|
|
||||
candidates[locale] ||= []
|
||||
candidates[locale] << item
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def translate_items
|
||||
candidates = self.item_translation_candidates
|
||||
|
||||
until candidates.empty?
|
||||
# Organize known items by ID
|
||||
items_by_id = {}
|
||||
@items.each { |i| items_by_id[i.id] = i }
|
||||
|
||||
# Fetch registry data in parallel
|
||||
registries = Parallel.map(candidates.keys, :in_threads => 8) do |locale|
|
||||
viewer_data = fetch_viewer_data(4, locale) # TODO: ew, don't copy-paste the default timeout
|
||||
[locale, viewer_data[:object_info_registry]]
|
||||
end
|
||||
|
||||
# Look up any newly applied items on this pet, just in case
|
||||
new_item_ids = []
|
||||
registries.each do |locale, registry|
|
||||
registry.each do |item_id, item_info|
|
||||
item_id = item_id.to_i
|
||||
new_item_ids << item_id unless items_by_id.has_key?(item_id)
|
||||
end
|
||||
end
|
||||
Item.includes(:translations).find(new_item_ids).each do |item|
|
||||
items_by_id[item.id] = item
|
||||
end
|
||||
|
||||
# Apply translations, and figure out what items are currently being worn
|
||||
current_items = Set.new
|
||||
registries.each do |locale, registry|
|
||||
registry.each do |item_id, item_info|
|
||||
item = items_by_id[item_id.to_i]
|
||||
item.add_origin_registry_info(item_info, locale)
|
||||
current_items << item
|
||||
end
|
||||
end
|
||||
|
||||
@items = current_items
|
||||
Item.transaction { @items.each { |i| i.save! if i.changed? } }
|
||||
|
||||
previous_candidates = candidates
|
||||
candidates = item_translation_candidates
|
||||
|
||||
if previous_candidates == candidates
|
||||
# This condition should never happen if Neopets responds with correct
|
||||
# data, but, if Neopets somehow responds with incorrect data, this
|
||||
# condition could throw us into an infinite loop if uncaught. Better
|
||||
# safe than sorry when working with external services.
|
||||
raise "No change when reloading #{name} for #{candidates}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
before_validation do
|
||||
pet_type.save!
|
||||
|
|
|
@ -148,6 +148,7 @@ class SwfAsset < ApplicationRecord
|
|||
self.type = 'object'
|
||||
self.zone_id = data[:zone_id].to_i
|
||||
self.url = data[:asset_url]
|
||||
self.zones_restrict = ""
|
||||
end
|
||||
|
||||
def mall_data=(data)
|
||||
|
|
Loading…
Reference in a new issue