give SWFs real, unique ID numbers

Lots of scary bugs were being caused by the fact that the possibly-duplicate Neopets ID
was being treated as an SWF's real primary key, meaning that a save meant for object swf
number 123 could be saved to biology swf number 123. Which is awful.

This update gives SWFs their own unique internal ID numbers. All external lookups still use
the remote ID and the type, meaning that the client side remains totally unchanged (phew).
However, all database relationships with SWFs use the new ID numbers, making everything
cleaner. Yay.

There are probably a few places where it would be appropriate to optimize certain lookups
that still depend on remote ID and type. Whatever. Today's goal was to remove crazy
glitches that have been floating around like mad. And I think that goal has been met.
This commit is contained in:
Emi Matchu 2012-01-12 17:17:59 -06:00
parent bdb2dfd97a
commit 696b2aedaf
94 changed files with 222 additions and 164 deletions

View file

@ -1,6 +1,6 @@
source 'http://rubygems.org' source 'http://rubygems.org'
gem 'rails', '3.0.4' gem 'rails', '3.0.5'
#gem 'sqlite3-ruby', '~> 1.3.1', :require => 'sqlite3' #gem 'sqlite3-ruby', '~> 1.3.1', :require => 'sqlite3'
gem 'compass', '~> 0.10.1' gem 'compass', '~> 0.10.1'

View file

@ -1,55 +1,61 @@
GIT GIT
remote: git://github.com/eventmachine/eventmachine.git remote: git://github.com/eventmachine/eventmachine.git
revision: 1d9b28eae110457ef3915aef380319a95697a167 revision: 69151c3ebb3e4ecf2bb9b6e2fab2022dc34f8541
specs: specs:
eventmachine (1.0.0.beta.2) eventmachine (1.0.0.beta.4)
GIT GIT
remote: git://github.com/igrigorik/em-http-request.git remote: git://github.com/igrigorik/em-http-request.git
revision: bbf9c11e02aaa91f5d1149319dcab59f410426e8 revision: ce50f322ce08d43a4a747cf333ea576765d764c4
specs: specs:
em-http-request (0.3.0) em-http-request (1.0.1)
addressable (>= 2.0.0) addressable (>= 2.2.3)
escape_utils cookiejar
eventmachine (>= 0.12.9) em-socksify
eventmachine (>= 1.0.0.beta.4)
http_parser.rb (>= 0.5.3)
GIT GIT
remote: git://github.com/igrigorik/em-mysqlplus.git remote: git://github.com/igrigorik/em-mysqlplus.git
revision: 35320562abc914cc7d9fd203abb746f99796739e revision: 11d6e1123654b948c1d0a8c9d9077e82420b2846
specs: specs:
em-mysqlplus (0.1.5) em-mysqlplus (0.1.5)
eventmachine (>= 0.12.9) eventmachine (>= 0.12.9)
GIT GIT
remote: git://github.com/igrigorik/em-synchrony.git remote: git://github.com/igrigorik/em-synchrony.git
revision: f59169c5c8f893336802f1de2970ee9dd8755158 revision: c7209a58f9eb92e1dc81fb141297f9f257c2fdcb
specs: specs:
em-synchrony (0.2.0) em-synchrony (1.0.0)
eventmachine (>= 0.12.9) eventmachine (>= 1.0.0.beta.1)
GIT GIT
remote: git://github.com/oldmoe/mysqlplus.git remote: git://github.com/oldmoe/mysqlplus.git
revision: 2daef86c487ec1c531ecfe84ed342d15a1c89554 revision: 3dbaa7c00ff0bb75ad9538cdef176c72de35d231
specs: specs:
mysqlplus (0.1.1) mysqlplus (0.1.1)
GIT GIT
remote: git://github.com/rubyamf/rocketamf.git remote: git://github.com/rubyamf/rocketamf.git
revision: fdef9d836f1ed27b06ce669ea05122fa0dec4a12 revision: ed82db7659f624d6c3ca244e4127dad270a484c7
specs: specs:
RocketAMF (1.0.0) RocketAMF (1.0.0)
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
POpen4 (0.1.4)
Platform (>= 0.4.0)
open4
Platform (0.4.0)
aaronh-chronic (0.3.9) aaronh-chronic (0.3.9)
abstract (1.0.0) abstract (1.0.0)
actionmailer (3.0.4) actionmailer (3.0.5)
actionpack (= 3.0.4) actionpack (= 3.0.5)
mail (~> 2.2.15) mail (~> 2.2.15)
actionpack (3.0.4) actionpack (3.0.5)
activemodel (= 3.0.4) activemodel (= 3.0.5)
activesupport (= 3.0.4) activesupport (= 3.0.5)
builder (~> 2.1.2) builder (~> 2.1.2)
erubis (~> 2.6.6) erubis (~> 2.6.6)
i18n (~> 0.4) i18n (~> 0.4)
@ -57,83 +63,88 @@ GEM
rack-mount (~> 0.6.13) rack-mount (~> 0.6.13)
rack-test (~> 0.5.7) rack-test (~> 0.5.7)
tzinfo (~> 0.3.23) tzinfo (~> 0.3.23)
activemodel (3.0.4) activemodel (3.0.5)
activesupport (= 3.0.4) activesupport (= 3.0.5)
builder (~> 2.1.2) builder (~> 2.1.2)
i18n (~> 0.4) i18n (~> 0.4)
activerecord (3.0.4) activerecord (3.0.5)
activemodel (= 3.0.4) activemodel (= 3.0.5)
activesupport (= 3.0.4) activesupport (= 3.0.5)
arel (~> 2.0.2) arel (~> 2.0.2)
tzinfo (~> 0.3.23) tzinfo (~> 0.3.23)
activeresource (3.0.4) activeresource (3.0.5)
activemodel (= 3.0.4) activemodel (= 3.0.5)
activesupport (= 3.0.4) activesupport (= 3.0.5)
activesupport (3.0.4) activesupport (3.0.5)
addressable (2.2.4) addressable (2.2.6)
arel (2.0.8) arel (2.0.10)
bcrypt-ruby (2.1.4) bcrypt-ruby (2.1.4)
builder (2.1.2) builder (2.1.2)
character-encodings (0.4.1) character-encodings (0.4.1)
closure-compiler (1.0.0) closure-compiler (1.1.4)
compass (0.10.6) compass (0.10.6)
haml (>= 3.0.4) haml (>= 3.0.4)
devise (1.1.5) cookiejar (0.3.0)
devise (1.1.9)
bcrypt-ruby (~> 2.1.2) bcrypt-ruby (~> 2.1.2)
warden (~> 1.0.2) warden (~> 1.0.2)
diff-lcs (1.1.2) diff-lcs (1.1.3)
em-socksify (0.1.0)
eventmachine
erubis (2.6.6) erubis (2.6.6)
abstract (>= 1.0.0) abstract (>= 1.0.0)
escape_utils (0.1.9) factory_girl (2.3.2)
factory_girl (1.3.3) activesupport
factory_girl_rails (1.0.1) factory_girl_rails (1.4.0)
factory_girl (~> 1.3) factory_girl (~> 2.3.0)
railties (>= 3.0.0) railties (>= 3.0.0)
haml (3.0.25) haml (3.0.25)
hoptoad_notifier (2.4.5) hoptoad_notifier (2.4.11)
activesupport activesupport
builder builder
i18n (0.5.0) http_parser.rb (0.5.3)
i18n (0.6.0)
jammit (0.5.4) jammit (0.5.4)
closure-compiler (>= 0.1.0) closure-compiler (>= 0.1.0)
yui-compressor (>= 0.9.1) yui-compressor (>= 0.9.1)
json (1.4.6) json (1.4.6)
mail (2.2.15) mail (2.2.19)
activesupport (>= 2.3.6) activesupport (>= 2.3.6)
i18n (>= 0.4.0) i18n (>= 0.4.0)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
memcache-client (1.8.5) memcache-client (1.8.5)
mime-types (1.16) mime-types (1.17.2)
msgpack (0.4.4) msgpack (0.4.6)
mysql2 (0.2.6) mysql2 (0.3.11)
nokogiri (1.5.0) nokogiri (1.5.0)
open4 (1.3.0)
openneo-auth-signatory (0.1.0) openneo-auth-signatory (0.1.0)
ruby-hmac ruby-hmac
polyglot (0.3.1) polyglot (0.3.3)
rack (1.2.3) rack (1.2.5)
rack-fiber_pool (0.9.1) rack-fiber_pool (0.9.2)
rack-mount (0.6.13) rack-mount (0.6.14)
rack (>= 1.0.0) rack (>= 1.0.0)
rack-test (0.5.7) rack-test (0.5.7)
rack (>= 1.0) rack (>= 1.0)
rails (3.0.4) rails (3.0.5)
actionmailer (= 3.0.4) actionmailer (= 3.0.5)
actionpack (= 3.0.4) actionpack (= 3.0.5)
activerecord (= 3.0.4) activerecord (= 3.0.5)
activeresource (= 3.0.4) activeresource (= 3.0.5)
activesupport (= 3.0.4) activesupport (= 3.0.5)
bundler (~> 1.0) bundler (~> 1.0)
railties (= 3.0.4) railties (= 3.0.5)
railties (3.0.4) railties (3.0.5)
actionpack (= 3.0.4) actionpack (= 3.0.5)
activesupport (= 3.0.4) activesupport (= 3.0.5)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (~> 0.14.4) thor (~> 0.14.4)
rake (0.8.7) rake (0.9.2.2)
rdiscount (1.6.8) rdiscount (1.6.8)
redis (2.2.1) redis (2.2.2)
redis-namespace (1.0.3) redis-namespace (1.1.0)
redis (< 3.0.0) redis (< 3.0.0)
resque (1.15.0) resque (1.15.0)
json (~> 1.4.6) json (~> 1.4.6)
@ -143,9 +154,9 @@ GEM
resque-retry (0.1.0) resque-retry (0.1.0)
resque (>= 1.8.0) resque (>= 1.8.0)
resque-scheduler (>= 1.8.0) resque-scheduler (>= 1.8.0)
resque-scheduler (2.0.0.d) resque-scheduler (2.0.0.e)
redis (>= 2.0.1) redis (>= 2.0.1)
resque (>= 1.8.0) resque (>= 1.15.0)
rufus-scheduler rufus-scheduler
right_aws (2.1.0) right_aws (2.1.0)
right_http_connection (>= 1.2.5) right_http_connection (>= 1.2.5)
@ -163,28 +174,30 @@ GEM
rspec-rails (2.0.1) rspec-rails (2.0.1)
rspec (~> 2.0.0) rspec (~> 2.0.0)
ruby-hmac (0.4.0) ruby-hmac (0.4.0)
rufus-scheduler (2.0.9) rufus-scheduler (2.0.16)
tzinfo (>= 0.3.23) tzinfo (>= 0.3.23)
sanitize (2.0.3) sanitize (2.0.3)
nokogiri (< 1.6, >= 1.4.4) nokogiri (< 1.6, >= 1.4.4)
sinatra (1.2.6) sinatra (1.2.8)
rack (~> 1.1) rack (~> 1.1)
tilt (< 2.0, >= 1.2.2) tilt (>= 1.2.2, < 2.0)
swf_converter (0.0.3) swf_converter (0.0.3)
thor (0.14.6) thor (0.14.6)
tilt (1.3.2) tilt (1.3.3)
treetop (1.4.9) treetop (1.4.10)
polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.28) tzinfo (0.3.31)
vegas (0.1.8) vegas (0.1.8)
rack (>= 1.0.0) rack (>= 1.0.0)
warden (1.0.3) warden (1.0.6)
rack (>= 1.0.0) rack (>= 1.0)
whenever (0.6.2) whenever (0.6.8)
aaronh-chronic (>= 0.3.9) aaronh-chronic (>= 0.3.9)
activesupport (>= 2.3.4) activesupport (>= 2.3.4)
will_paginate (3.0.pre2) will_paginate (3.0.2)
yui-compressor (0.9.3) yui-compressor (0.9.6)
POpen4 (>= 0.1.4)
PLATFORMS PLATFORMS
ruby ruby
@ -210,7 +223,7 @@ DEPENDENCIES
nokogiri (~> 1.5.0) nokogiri (~> 1.5.0)
openneo-auth-signatory (~> 0.1.0) openneo-auth-signatory (~> 0.1.0)
rack-fiber_pool rack-fiber_pool
rails (= 3.0.4) rails (= 3.0.5)
rdiscount (~> 1.6.5) rdiscount (~> 1.6.5)
resque (~> 1.15.0) resque (~> 1.15.0)
resque-retry (~> 0.1.0) resque-retry (~> 0.1.0)

View file

@ -3,14 +3,16 @@ class BrokenImageReportsController < ApplicationController
ids = params[:asset_ids] ids = params[:asset_ids]
assets = SwfAsset.arel_table assets = SwfAsset.arel_table
@swf_assets = SwfAsset.where(:has_image => true).where(( @swf_assets = SwfAsset.where(:has_image => true).where((
assets[:id].in(ids[:biology]).and(assets[:type].eq('biology')) assets[:remote_id].in(ids[:biology]).and(assets[:type].eq('biology'))
).or( ).or(
assets[:id].in(ids[:object]).and(assets[:type].eq('object')) assets[:remote_id].in(ids[:object]).and(assets[:type].eq('object'))
)) ))
end end
def create def create
swf_asset = SwfAsset.find params[:swf_asset_id] swf_asset = SwfAsset.where(:type => params[:swf_asset_type]).
find_by_remote_id(params[:swf_asset_remote_id])
if swf_asset.report_broken if swf_asset.report_broken
flash[:success] = "Thanks! This image will be reconverted soon. If it " + flash[:success] = "Thanks! This image will be reconverted soon. If it " +

View file

@ -29,10 +29,10 @@ class SwfAssetsController < ApplicationController
elsif params[:ids] elsif params[:ids]
@swf_assets = [] @swf_assets = []
if params[:ids][:biology] if params[:ids][:biology]
@swf_assets += SwfAsset.biology_assets.where(:id => params[:ids][:biology]).all @swf_assets += SwfAsset.biology_assets.where(:remote_id => params[:ids][:biology]).all
end end
if params[:ids][:object] if params[:ids][:object]
@swf_assets += SwfAsset.object_assets.where(:id => params[:ids][:object]).all @swf_assets += SwfAsset.object_assets.where(:remote_id => params[:ids][:object]).all
end end
end end
if @swf_assets if @swf_assets

View file

@ -8,8 +8,8 @@ class AssetImageConversionRequest
@queue = :requested_asset_images @queue = :requested_asset_images
def self.perform(asset_type, asset_id) def self.perform(asset_id)
asset = SwfAsset.where(:type => asset_type).find(asset_id) asset = SwfAsset.find(asset_id)
asset.convert_swf_if_not_converted! asset.convert_swf_if_not_converted!
end end

View file

@ -7,10 +7,8 @@ class Item < ActiveRecord::Base
has_many :closet_hangers has_many :closet_hangers
has_one :contribution, :as => :contributed has_one :contribution, :as => :contributed
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id', has_many :parent_swf_asset_relationships, :as => :parent
:conditions => {:swf_asset_type => SwfAssetType} has_many :swf_assets, :through => :parent_swf_asset_relationships
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :object_asset,
:conditions => {:type => SwfAssetType}
attr_writer :current_body_id, :owned, :wanted attr_writer :current_body_id, :owned, :wanted
@ -29,14 +27,7 @@ class Item < ActiveRecord::Base
scope :alphabetize, order('name ASC') scope :alphabetize, order('name ASC')
scope :join_swf_assets, joins("INNER JOIN #{ParentSwfAssetRelationship.table_name} psa ON psa.swf_asset_type = 'object' AND psa.parent_id = objects.id"). scope :join_swf_assets, joins(:swf_assets).group('objects.id')
joins("INNER JOIN #{SwfAsset.table_name} swf_assets ON swf_assets.id = psa.swf_asset_id").
group('objects.id')
scope :without_swf_assets, joins(
"LEFT JOIN #{ParentSwfAssetRelationship.table_name} psa ON psa.swf_asset_type = 'object' AND psa.parent_id = #{table_name}.id " +
"LEFT JOIN #{SwfAsset.table_name} sa ON sa.type = 'object' AND sa.id = psa.swf_asset_id"
).where('sa.id IS NULL')
scope :newest, order(arel_table[:created_at].desc) if arel_table[:created_at] scope :newest, order(arel_table[:created_at].desc) if arel_table[:created_at]
@ -191,15 +182,13 @@ class Item < ActiveRecord::Base
# but doesn't in this sample, the two have been unbound. Delete the # but doesn't in this sample, the two have been unbound. Delete the
# relationship. # relationship.
ids_to_delete = self.parent_swf_asset_relationships. ids_to_delete = self.parent_swf_asset_relationships.
select(:id). select(:remote_id).
joins(:object_asset). joins(:swf_asset).
where(rels[:swf_asset_id].not_in(new_swf_asset_ids)). where(rels[:swf_asset_id].not_in(new_swf_asset_ids)).
where(swf_assets[:body_id].in([@current_body_id, 0])). where(swf_assets[:body_id].in([@current_body_id, 0])).
map(&:id) map(&:remote_id)
unless ids_to_delete.empty? unless ids_to_delete.empty?
ParentSwfAssetRelationship. self.parent_swf_asset_relationships.
where(rels[:parent_id].eq(self.id)).
where(rels[:swf_asset_type].eq(SwfAssetType)).
where(rels[:swf_asset_id].in(ids_to_delete)). where(rels[:swf_asset_id].in(ids_to_delete)).
delete_all delete_all
end end
@ -241,7 +230,10 @@ class Item < ActiveRecord::Base
swf_assets_by_id[id] = swf_asset swf_assets_by_id[id] = swf_asset
swf_asset_ids << id swf_asset_ids << id
end end
SwfAsset.select('id, parent_id').object_assets.joins(:object_asset_relationships). SwfAsset.select([
SwfAsset.arel_table[:id],
ParentSwfAssetRelationship.arel_table[:parent_id]
]).object_assets.joins(:parent_swf_asset_relationships).
where(SwfAsset.arel_table[:id].in(swf_asset_ids)).each do |row| where(SwfAsset.arel_table[:id].in(swf_asset_ids)).each do |row|
item_id = row.parent_id.to_i item_id = row.parent_id.to_i
swf_assets_by_parent_id[item_id] ||= [] swf_assets_by_parent_id[item_id] ||= []
@ -291,7 +283,7 @@ class Item < ActiveRecord::Base
asset_registry.each do |asset_id, asset_data| asset_registry.each do |asset_id, asset_data|
swf_asset_ids << asset_id.to_i if asset_data swf_asset_ids << asset_id.to_i if asset_data
end end
existing_swf_assets = SwfAsset.object_assets.find_all_by_id swf_asset_ids existing_swf_assets = SwfAsset.object_assets.find_all_by_remote_id swf_asset_ids
existing_swf_assets_by_id = {} existing_swf_assets_by_id = {}
existing_swf_assets.each do |swf_asset| existing_swf_assets.each do |swf_asset|
existing_swf_assets_by_id[swf_asset.id] = swf_asset existing_swf_assets_by_id[swf_asset.id] = swf_asset
@ -318,7 +310,7 @@ class Item < ActiveRecord::Base
swf_asset = existing_swf_assets_by_id[swf_asset_id] swf_asset = existing_swf_assets_by_id[swf_asset_id]
unless swf_asset unless swf_asset
swf_asset = SwfAsset.new swf_asset = SwfAsset.new
swf_asset.id = swf_asset_id swf_asset.remote_id = swf_asset_id
end end
swf_asset.origin_object_data = asset_data swf_asset.origin_object_data = asset_data
swf_asset.origin_pet_type = pet_type swf_asset.origin_pet_type = pet_type
@ -327,11 +319,10 @@ class Item < ActiveRecord::Base
relationship = existing_relationships_by_item_id_and_swf_asset_id[item.id][swf_asset_id] rescue nil relationship = existing_relationships_by_item_id_and_swf_asset_id[item.id][swf_asset_id] rescue nil
unless relationship unless relationship
relationship = ParentSwfAssetRelationship.new relationship = ParentSwfAssetRelationship.new
relationship.parent_id = item.id relationship.parent = item
relationship.swf_asset_type = SwfAssetType
relationship.swf_asset_id = swf_asset.id relationship.swf_asset_id = swf_asset.id
end end
relationship.object_asset = swf_asset relationship.swf_asset = swf_asset
relationships_by_item_id[item_id] ||= [] relationships_by_item_id[item_id] ||= []
relationships_by_item_id[item_id] << relationship relationships_by_item_id[item_id] << relationship
end end
@ -787,7 +778,7 @@ class Item < ActiveRecord::Base
# the zone requirement. If that max was NULL, return the object. # the zone requirement. If that max was NULL, return the object.
item_ids = select(arel_table[:id]).joins( item_ids = select(arel_table[:id]).joins(
"LEFT JOIN #{ParentSwfAssetRelationship.table_name} #{psa.name} ON " + "LEFT JOIN #{ParentSwfAssetRelationship.table_name} #{psa.name} ON " +
psa[:swf_asset_type].eq(SwfAssetType). psa[:parent_type].eq(self.name).
and(psa[:parent_id].eq(arel_table[:id])). and(psa[:parent_id].eq(arel_table[:id])).
to_sql to_sql
). ).

View file

@ -1,17 +1,12 @@
class ParentSwfAssetRelationship < ActiveRecord::Base class ParentSwfAssetRelationship < ActiveRecord::Base
set_table_name 'parents_swf_assets' set_table_name 'parents_swf_assets'
belongs_to :item, :foreign_key => 'parent_id' belongs_to :parent, :polymorphic => true
belongs_to :biology_asset, :class_name => 'SwfAsset', :foreign_key => 'swf_asset_id', :conditions => {:type => 'biology'} belongs_to :swf_asset
belongs_to :object_asset, :class_name => 'SwfAsset', :foreign_key => 'swf_asset_id', :conditions => {:type => 'object'}
def swf_asset
self.swf_asset_type == 'biology' ? self.biology_asset : self.object_asset
end
def item=(replacement) def item=(replacement)
self.parent_id = replacement.id self.parent = replacement
end end
def pet_state def pet_state
@ -19,6 +14,6 @@ class ParentSwfAssetRelationship < ActiveRecord::Base
end end
def pet_state=(replacement) def pet_state=(replacement)
self.parent_id = replacement.id self.parent = replacement
end end
end end

View file

@ -1,12 +1,10 @@
class PetState < ActiveRecord::Base class PetState < ActiveRecord::Base
SwfAssetType = 'biology' SwfAssetType = 'biology'
has_many :contributions, :as => :contributed # in case of duplicates being merged has_many :contributions, :as => :contributed # in case of duplicates being merged
has_many :outfits has_many :outfits
has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id', has_many :parent_swf_asset_relationships, :foreign_key => 'parent_id'
:conditions => {:swf_asset_type => SwfAssetType} has_many :swf_assets, :through => :parent_swf_asset_relationships
has_many :swf_assets, :through => :parent_swf_asset_relationships, :source => :biology_asset,
:conditions => {:type => SwfAssetType}
belongs_to :pet_type belongs_to :pet_type
@ -14,9 +12,9 @@ class PetState < ActiveRecord::Base
bio_effect_zone_id = 4 bio_effect_zone_id = 4
scope :emotion_order, joins(:parent_swf_asset_relationships). scope :emotion_order, joins(:parent_swf_asset_relationships).
joins("LEFT JOIN swf_assets effect_assets ON effect_assets.id = parents_swf_assets.swf_asset_id AND effect_assets.type = 'biology' AND effect_assets.zone_id = #{bio_effect_zone_id}"). joins("LEFT JOIN swf_assets effect_assets ON effect_assets.remote_id = parents_swf_assets.swf_asset_id AND effect_assets.zone_id = #{bio_effect_zone_id}").
group("pet_states.id"). group("pet_states.id").
order("COUNT(effect_assets.id) ASC, COUNT(parents_swf_assets.swf_asset_id) DESC, SUM(parents_swf_assets.swf_asset_id) ASC") order("COUNT(effect_assets.remote_id) ASC, COUNT(parents_swf_assets.swf_asset_id) DESC, SUM(parents_swf_assets.swf_asset_id) ASC")
def reassign_children_to!(main_pet_state) def reassign_children_to!(main_pet_state)
self.contributions.each do |contribution| self.contributions.each do |contribution|
@ -76,7 +74,7 @@ class PetState < ActiveRecord::Base
swf_asset_ids_str swf_asset_ids_str
) )
end end
existing_swf_assets = SwfAsset.biology_assets.find_all_by_id(swf_asset_ids) existing_swf_assets = SwfAsset.biology_assets.find_all_by_remote_id(swf_asset_ids)
existing_swf_assets_by_id = {} existing_swf_assets_by_id = {}
existing_swf_assets.each do |swf_asset| existing_swf_assets.each do |swf_asset|
existing_swf_assets_by_id[swf_asset.id] = swf_asset existing_swf_assets_by_id[swf_asset.id] = swf_asset
@ -95,18 +93,17 @@ class PetState < ActiveRecord::Base
swf_asset = existing_swf_assets_by_id[swf_asset_id] swf_asset = existing_swf_assets_by_id[swf_asset_id]
unless swf_asset unless swf_asset
swf_asset = SwfAsset.new swf_asset = SwfAsset.new
swf_asset.id = swf_asset_id swf_asset.remote_id = swf_asset_id
end end
swf_asset.origin_biology_data = asset_info swf_asset.origin_biology_data = asset_info
swf_asset.origin_pet_type = pet_type swf_asset.origin_pet_type = pet_type
relationship = existing_relationships_by_swf_asset_id[swf_asset_id] relationship = existing_relationships_by_swf_asset_id[swf_asset_id]
unless relationship unless relationship
relationship ||= ParentSwfAssetRelationship.new relationship ||= ParentSwfAssetRelationship.new
relationship.parent_id = pet_state.id relationship.parent = pet_state
relationship.swf_asset_type = SwfAssetType
relationship.swf_asset_id = swf_asset.id relationship.swf_asset_id = swf_asset.id
end end
relationship.biology_asset = swf_asset relationship.swf_asset = swf_asset
relationships << relationship relationships << relationship
end end
end end

View file

@ -41,7 +41,11 @@ class PetType < ActiveRecord::Base
def as_json(options={}) def as_json(options={})
if options[:for] == 'wardrobe' if options[:for] == 'wardrobe'
{:id => id, :body_id => body_id, :pet_state_ids => pet_states.select('pet_states.id').emotion_order.map(&:id)} {
:id => id,
:body_id => body_id,
:pet_state_ids => pet_state_ids
}
else else
{:image_hash => image_hash} {:image_hash => image_hash}
end end
@ -103,7 +107,8 @@ class PetType < ActiveRecord::Base
species_condition = condition species_condition = condition
end end
end end
unneeded_item_ids = Item.select(items[:id]).joins(:parent_swf_asset_relationships => :object_asset). unneeded_item_ids = Item.select(items[:id]).
joins(:parent_swf_asset_relationships => :swf_asset).
where(SwfAsset.arel_table[:body_id].in([0, self.body_id])).map(&:id) where(SwfAsset.arel_table[:body_id].in([0, self.body_id])).map(&:id)
Item.where(items[:id].not_in(unneeded_item_ids)). Item.where(items[:id].not_in(unneeded_item_ids)).
where(species_condition) where(species_condition)
@ -113,6 +118,10 @@ class PetType < ActiveRecord::Base
pet_state = PetState.from_pet_type_and_biology_info(self, biology) pet_state = PetState.from_pet_type_and_biology_info(self, biology)
pet_state pet_state
end end
def pet_state_ids
pet_states.select('pet_states.id').emotion_order.map(&:id)
end
before_save do before_save do
if @origin_pet && @origin_pet.name =~ IMAGE_CPN_ACCEPTABLE_NAME if @origin_pet && @origin_pet.name =~ IMAGE_CPN_ACCEPTABLE_NAME

View file

@ -57,7 +57,7 @@ class SwfAsset < ActiveRecord::Base
end end
def s3_path def s3_path
"#{self['type']}/#{s3_partition_path}#{self.id}" "#{self['type']}/#{s3_partition_path}#{self.remote_id}"
end end
def s3_url(size) def s3_url(size)
@ -68,7 +68,7 @@ class SwfAsset < ActiveRecord::Base
PARTITION_DIGITS = 3 PARTITION_DIGITS = 3
PARTITION_ID_LENGTH = PARTITION_COUNT * PARTITION_DIGITS PARTITION_ID_LENGTH = PARTITION_COUNT * PARTITION_DIGITS
def s3_partition_path def s3_partition_path
(id / 10**PARTITION_DIGITS).to_s.rjust(PARTITION_ID_LENGTH, '0').tap do |id_str| (remote_id / 10**PARTITION_DIGITS).to_s.rjust(PARTITION_ID_LENGTH, '0').tap do |id_str|
PARTITION_COUNT.times do |n| PARTITION_COUNT.times do |n|
id_str.insert(PARTITION_ID_LENGTH - (n * PARTITION_DIGITS), '/') id_str.insert(PARTITION_ID_LENGTH - (n * PARTITION_DIGITS), '/')
end end
@ -88,7 +88,7 @@ class SwfAsset < ActiveRecord::Base
if image_requested? if image_requested?
false false
else else
Resque.enqueue(AssetImageConversionRequest, self.type, self.id) Resque.enqueue(AssetImageConversionRequest, self.id)
self.image_requested = true self.image_requested = true
save! save!
true true
@ -100,7 +100,7 @@ class SwfAsset < ActiveRecord::Base
return false return false
end end
Resque.enqueue(AssetImageConversionRequest::OnBrokenImageReport, self.type, self.id) Resque.enqueue(AssetImageConversionRequest::OnBrokenImageReport, self.id)
self.reported_broken_at = Time.now self.reported_broken_at = Time.now
self.save self.save
end end
@ -119,8 +119,7 @@ class SwfAsset < ActiveRecord::Base
attr_accessor :item attr_accessor :item
has_one :contribution, :as => :contributed has_one :contribution, :as => :contributed
has_many :object_asset_relationships, :class_name => 'ParentSwfAssetRelationship', has_many :parent_swf_asset_relationships
:conditions => {:swf_asset_type => 'object'}
delegate :depth, :to => :zone delegate :depth, :to => :zone
@ -144,7 +143,7 @@ class SwfAsset < ActiveRecord::Base
scope :biology_assets, where(:type => PetState::SwfAssetType) scope :biology_assets, where(:type => PetState::SwfAssetType)
scope :object_assets, where(:type => Item::SwfAssetType) scope :object_assets, where(:type => Item::SwfAssetType)
scope :for_item_ids, lambda { |item_ids| scope :for_item_ids, lambda { |item_ids|
joins(:object_asset_relationships). joins(:parent_swf_asset_relationships).
where(ParentSwfAssetRelationship.arel_table[:parent_id].in(item_ids)) where(ParentSwfAssetRelationship.arel_table[:parent_id].in(item_ids))
} }
@ -154,7 +153,7 @@ class SwfAsset < ActiveRecord::Base
def as_json(options={}) def as_json(options={})
json = { json = {
:id => id, :id => remote_id,
:type => type, :type => type,
:depth => depth, :depth => depth,
:body_id => body_id, :body_id => body_id,
@ -236,7 +235,7 @@ class SwfAsset < ActiveRecord::Base
end end
after_commit :on => :create do after_commit :on => :create do
Resque.enqueue(AssetImageConversionRequest::OnCreation, self.type, self.id) Resque.enqueue(AssetImageConversionRequest::OnCreation, self.id)
end end
class DownloadError < Exception;end class DownloadError < Exception;end

View file

@ -1,12 +0,0 @@
module SwfAssetParent
def swf_assets
rels = ParentSwfAssetRelationship.arel_table
type = self.class::SwfAssetType
ids = ParentSwfAssetRelationship.
where(rels[:parent_id].eq(id).and(rels[:swf_asset_type].eq(type))).
select(rels[:swf_asset_id]).
all.map(&:swf_asset_id)
assets = SwfAsset.arel_table
SwfAsset.where(assets[:id].in(ids).and(assets[:type].eq(type)))
end
end

View file

@ -15,7 +15,8 @@
= link_to image_tag(swf_asset.s3_url([150, 150])), swf_asset.url = link_to image_tag(swf_asset.s3_url([150, 150])), swf_asset.url
- unless swf_asset.image_pending_repair? - unless swf_asset.image_pending_repair?
= form_tag(:action => :create) do = form_tag(:action => :create) do
= hidden_field_tag 'swf_asset_id', swf_asset.id = hidden_field_tag 'swf_asset_remote_id', swf_asset.remote_id
= hidden_field_tag 'swf_asset_type', swf_asset.type
= submit_tag 'Report as broken' = submit_tag 'Report as broken'
- if swf_asset.converted_at? - if swf_asset.converted_at?

View file

@ -0,0 +1,7 @@
<p class="warning">
Dress to Impress is scheduled to go down for maintenance
<strong>tonight at 6 PM NST</strong>.
The <a href="http://oldimpress.openneo.net/">old server</a> will still be
online, and we expect to be done in less than an hour.
Thanks for understanding.
</p>

View file

@ -0,0 +1,55 @@
class RenameSwfAssetsIdToRemoteId < ActiveRecord::Migration
def self.up
rename_column :swf_assets, :id, :remote_id
add_column :swf_assets, :id, :primary_key
Contribution.where(:contributed_type => 'SwfAsset').find_each do |c|
# Use real IDs instead of remote IDs
swf_asset = SwfAsset.object_assets.
find_by_remote_id(c.contributed_id)
c.contributed_id = swf_asset.id
c.save!
end
puts "Updated contributions"
add_column :parents_swf_assets, :id, :primary_key
add_column :parents_swf_assets, :parent_type, :string, :null => false,
:limit => 8
ParentSwfAssetRelationship.all.each do |rel|
swf_asset = SwfAsset.where(:type => rel.swf_asset_type).
find_by_remote_id(rel.swf_asset_id)
rel.swf_asset_id = swf_asset.id
rel.parent_type = (rel.swf_asset_type == 'biology') ? 'PetState' : 'Item'
rel.save!
end
puts "Updated parent/asset relationships"
remove_column :parents_swf_assets, :swf_asset_type
end
def self.down
add_column :parents_swf_assets, :swf_asset_type, :string,
:null => false, :limit => 7
ParentSwfAssetRelationship.all.each do |rel|
swf_asset = SwfAsset.find(rel.swf_asset_id)
rel.swf_asset_id = swf_asset.remote_id
rel.swf_asset_type = swf_asset.type
rel.save!
end
remove_column :parents_swf_assets, :parent_type
remove_column :parents_swf_assets, :id
puts "Updated parent/asset relationships"
Contribution.where(:contributed_type => 'SwfAsset').find_each do |c|
# Use remote IDs instead of real IDs
swf_asset = SwfAsset.find(c.swf_asset_id)
c.contributed_id = swf_asset.remote_id
c.save!
end
puts "Updated contributions"
remove_column :swf_assets, :id
rename_column :swf_assets, :remote_id, :id
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110807212936) do ActiveRecord::Schema.define(:version => 20120112204234) do
create_table "auth_servers", :force => true do |t| create_table "auth_servers", :force => true do |t|
t.string "short_name", :limit => 10, :null => false t.string "short_name", :limit => 10, :null => false
@ -40,6 +40,11 @@ ActiveRecord::Schema.define(:version => 20110807212936) do
t.integer "visibility", :default => 1, :null => false t.integer "visibility", :default => 1, :null => false
end end
create_table "colors", :force => true do |t|
t.string "name"
t.boolean "basic", :default => false, :null => false
end
create_table "contributions", :force => true do |t| create_table "contributions", :force => true do |t|
t.string "contributed_type", :limit => 8, :null => false t.string "contributed_type", :limit => 8, :null => false
t.integer "contributed_id", :null => false t.integer "contributed_id", :null => false
@ -102,13 +107,13 @@ ActiveRecord::Schema.define(:version => 20110807212936) do
t.boolean "starred", :default => false, :null => false t.boolean "starred", :default => false, :null => false
end end
create_table "parents_swf_assets", :id => false, :force => true do |t| create_table "parents_swf_assets", :force => true do |t|
t.integer "parent_id", :limit => 3, :null => false t.integer "parent_id", :limit => 3, :null => false
t.integer "swf_asset_id", :limit => 3, :null => false t.integer "swf_asset_id", :limit => 3, :null => false
t.string "swf_asset_type", :limit => 7, :null => false t.string "parent_type", :limit => 8, :null => false
end end
add_index "parents_swf_assets", ["parent_id", "swf_asset_id", "swf_asset_type"], :name => "unique_parents_swf_assets", :unique => true add_index "parents_swf_assets", ["parent_id", "swf_asset_id"], :name => "unique_parents_swf_assets", :unique => true
add_index "parents_swf_assets", ["parent_id"], :name => "parent_swf_assets_parent_id" add_index "parents_swf_assets", ["parent_id"], :name => "parent_swf_assets_parent_id"
add_index "parents_swf_assets", ["swf_asset_id"], :name => "parents_swf_assets_swf_asset_id" add_index "parents_swf_assets", ["swf_asset_id"], :name => "parents_swf_assets_swf_asset_id"
@ -151,13 +156,9 @@ ActiveRecord::Schema.define(:version => 20110807212936) do
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "schema_info", :id => false, :force => true do |t| create_table "swf_assets", :force => true do |t|
t.integer "version", :default => 0, :null => false
end
create_table "swf_assets", :id => false, :force => true do |t|
t.string "type", :limit => 7, :null => false t.string "type", :limit => 7, :null => false
t.integer "id", :limit => 3, :null => false t.integer "remote_id", :limit => 3, :null => false
t.text "url", :limit => 16777215, :null => false t.text "url", :limit => 16777215, :null => false
t.integer "zone_id", :limit => 1, :null => false t.integer "zone_id", :limit => 1, :null => false
t.text "zones_restrict", :null => false t.text "zones_restrict", :null => false
@ -170,7 +171,7 @@ ActiveRecord::Schema.define(:version => 20110807212936) do
end end
add_index "swf_assets", ["body_id"], :name => "swf_assets_body_id_and_object_id" add_index "swf_assets", ["body_id"], :name => "swf_assets_body_id_and_object_id"
add_index "swf_assets", ["type", "id"], :name => "swf_assets_type_and_id" add_index "swf_assets", ["type", "remote_id"], :name => "swf_assets_type_and_id"
add_index "swf_assets", ["zone_id"], :name => "idx_swf_assets_zone_id" add_index "swf_assets", ["zone_id"], :name => "idx_swf_assets_zone_id"
create_table "topics", :force => true do |t| create_table "topics", :force => true do |t|

BIN
vendor/cache/POpen4-0.1.4.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/Platform-0.4.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/actionmailer-3.0.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/actionpack-3.0.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activemodel-3.0.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activerecord-3.0.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/activesupport-3.0.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/addressable-2.2.6.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/arel-2.0.10.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/closure-compiler-1.1.4.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/cookiejar-0.3.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/devise-1.1.9.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/diff-lcs-1.1.3.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/em-socksify-0.1.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/factory_girl-2.3.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/hoptoad_notifier-2.4.11.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/http_parser.rb-0.5.3.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/i18n-0.6.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/mail-2.2.19.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/mime-types-1.17.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/msgpack-0.4.6.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/mysql2-0.3.11.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/open4-1.3.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/polyglot-0.3.3.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/rack-1.2.5.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/rack-fiber_pool-0.9.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/rake-0.9.2.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/redis-2.2.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/redis-namespace-1.1.0.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/rufus-scheduler-2.0.16.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/sinatra-1.2.8.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/tilt-1.3.3.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/treetop-1.4.10.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/tzinfo-0.3.31.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/warden-1.0.6.gem vendored Normal file

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/whenever-0.6.8.gem vendored Normal file

Binary file not shown.

BIN
vendor/cache/will_paginate-3.0.2.gem vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
vendor/cache/yui-compressor-0.9.6.gem vendored Normal file

Binary file not shown.