fix some mall spider bugs, including not having all the attributes it needed for search indexing
This commit is contained in:
parent
d767953ef3
commit
082119afe1
3 changed files with 15 additions and 9 deletions
|
@ -535,7 +535,6 @@ class Item < ActiveRecord::Base
|
||||||
def spider(item)
|
def spider(item)
|
||||||
puts " - Using #{@name} strategy"
|
puts " - Using #{@name} strategy"
|
||||||
exit = false
|
exit = false
|
||||||
Rails.logger.debug(@pet_types.inspect)
|
|
||||||
@pet_types.each do |pet_type|
|
@pet_types.each do |pet_type|
|
||||||
swf_assets = load_for_pet_type(item, pet_type)
|
swf_assets = load_for_pet_type(item, pet_type)
|
||||||
if swf_assets
|
if swf_assets
|
||||||
|
@ -571,14 +570,14 @@ class Item < ActiveRecord::Base
|
||||||
original_pet = Pet.select([:id, :name]).
|
original_pet = Pet.select([:id, :name]).
|
||||||
where(pet_type_id: pet_type.id).first
|
where(pet_type_id: pet_type.id).first
|
||||||
if original_pet.nil?
|
if original_pet.nil?
|
||||||
puts " - We have no more pets of type \##{pet_type.id}. Skipping"
|
puts " - We have no more pets of type \##{pet_type.id}; skipping."
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
pet_id = original_pet.id
|
pet_id = original_pet.id
|
||||||
pet_name = original_pet.name
|
pet_name = original_pet.name
|
||||||
pet_valid = nil
|
pet_valid = nil
|
||||||
begin
|
begin
|
||||||
pet = Pet.load(pet_name)
|
pet = Pet.load(pet_name, timeout: 10)
|
||||||
if pet.pet_type_id == pet_type.id
|
if pet.pet_type_id == pet_type.id
|
||||||
pet_valid = true
|
pet_valid = true
|
||||||
else
|
else
|
||||||
|
@ -590,6 +589,9 @@ class Item < ActiveRecord::Base
|
||||||
pet_valid = false
|
pet_valid = false
|
||||||
puts " - Pet #{pet_name} no longer exists; destroying and loading new pet"
|
puts " - Pet #{pet_name} no longer exists; destroying and loading new pet"
|
||||||
original_pet.destroy
|
original_pet.destroy
|
||||||
|
rescue Pet::DownloadError => e
|
||||||
|
puts " - Pet #{pet_name} timed out: #{e.message}; skipping."
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
if pet_valid
|
if pet_valid
|
||||||
swf_assets = load_for_pet_name(item, pet_type, pet_name)
|
swf_assets = load_for_pet_name(item, pet_type, pet_name)
|
||||||
|
@ -616,7 +618,6 @@ class Item < ActiveRecord::Base
|
||||||
if !data.empty? && data[item_id_key] && data[item_id_key]['asset_data']
|
if !data.empty? && data[item_id_key] && data[item_id_key]['asset_data']
|
||||||
data[item_id_key]['asset_data'].map do |asset_id_str, asset_data|
|
data[item_id_key]['asset_data'].map do |asset_id_str, asset_data|
|
||||||
item.zones_restrict = asset_data['restrict']
|
item.zones_restrict = asset_data['restrict']
|
||||||
item.save
|
|
||||||
swf_asset = SwfAsset.find_or_initialize_by_type_and_remote_id(SwfAssetType, asset_id_str.to_i)
|
swf_asset = SwfAsset.find_or_initialize_by_type_and_remote_id(SwfAssetType, asset_id_str.to_i)
|
||||||
swf_asset.type = SwfAssetType
|
swf_asset.type = SwfAssetType
|
||||||
swf_asset.body_id = pet_type.body_id
|
swf_asset.body_id = pet_type.body_id
|
||||||
|
@ -659,9 +660,14 @@ class Item < ActiveRecord::Base
|
||||||
def spider(item)
|
def spider(item)
|
||||||
puts "- Spidering for #{item.name}"
|
puts "- Spidering for #{item.name}"
|
||||||
Strategies[:start].spider(item)
|
Strategies[:start].spider(item)
|
||||||
item.last_spidered = Time.now
|
if item.swf_assets.present?
|
||||||
item.save
|
puts "- #{item.name} done spidering, saved last spidered timestamp"
|
||||||
puts "- #{item.name} done spidering, saved last spidered timestamp"
|
item.rarity_index = 500 # a decent assumption for mall items
|
||||||
|
item.last_spidered = Time.now
|
||||||
|
item.save!
|
||||||
|
else
|
||||||
|
puts "- #{item.name} found no models, so not saved"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_strategies
|
def build_strategies
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Pet < ActiveRecord::Base
|
||||||
options[:locale] ||= I18n.default_locale
|
options[:locale] ||= I18n.default_locale
|
||||||
|
|
||||||
I18n.with_locale(options[:locale]) do
|
I18n.with_locale(options[:locale]) do
|
||||||
viewer_data = fetch_viewer_data
|
viewer_data = fetch_viewer_data(options[:timeout])
|
||||||
pet_data = viewer_data[:custom_pet]
|
pet_data = viewer_data[:custom_pet]
|
||||||
|
|
||||||
self.pet_type = PetType.find_or_initialize_by_species_id_and_color_id(
|
self.pet_type = PetType.find_or_initialize_by_species_id_and_color_id(
|
||||||
|
|
|
@ -15,7 +15,7 @@ class PetType < ActiveRecord::Base
|
||||||
|
|
||||||
# Returns all pet types of a single standard color. The caller shouldn't care
|
# Returns all pet types of a single standard color. The caller shouldn't care
|
||||||
# which, though, in this implemention, it's always Blue. Don't depend on that.
|
# which, though, in this implemention, it's always Blue. Don't depend on that.
|
||||||
scope :single_standard_color, lambda { where(:color_id => Color.standard.first) }
|
scope :single_standard_color, lambda { where(:color_id => Color.basic.first) }
|
||||||
|
|
||||||
scope :nonstandard_colors, lambda { where(:color_id => Color.nonstandard) }
|
scope :nonstandard_colors, lambda { where(:color_id => Color.nonstandard) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue