nkallen / cache-money

A Write-Through Cacheing Library for ActiveRecord
Apache License 2.0
994 stars 107 forks source link

stack too deep error #8

Open mukundmr opened 14 years ago

mukundmr commented 14 years ago


?> x = Package.find_by_name "Platinum Pack"
  SQL (0.1ms)   SET SQL_AUTO_IS_NULL=0
  Package Columns (1.2ms)   SHOW FIELDS FROM `packages`
  Package Load (0.2ms)   SELECT \* FROM `packages` WHERE (`packages`.`name` = 'Platinum Pack') LIMIT 1
=> #

> > x.send :all_package_ids
> >   AssociatedPackage Columns (1.1ms)   SHOW FIELDS FROM `associated_packages`
> >   AssociatedPackage Load (0.2ms)   SELECT \* FROM `associated_packages` WHERE (`associated_packages`.`id` = 7) AND (`associated_packages`.package_id = 21) 
> > => [21, 20, 19]
> > x.send :all_package_ids

SystemStackError: stack level too deep
    from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/hash/except.rb:18:in `except!'
    from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/hash/except.rb:13:in`except'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:78:in `safe_options_for_cache?'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:52:in`cacheable?'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:52:in `each'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:52:in`cacheable?'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:15:in `perform'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:7:in`perform'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/finders.rb:24:in `find_every'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1583:in`find_one'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:1569:in `find_from_ids_without_cache'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:6:in`**send**'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:6:in `find_from_ids_without_cache'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:158:in`find_from_keys'
    from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.3/lib/active_support/core_ext/module/delegation.rb:122:in `to_proc'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/accessor.rb:17:in`call'
... 4742 levels...
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:19:in `perform'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:7:in`perform'
    from /opt/local/lib/ruby/gems/1.8/gems/nkallen-cache-money-0.2.5/lib/cash/finders.rb:24:in `find_every'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:615:in`find'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:635:in `all'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/association_collection.rb:379:in`send'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/association_collection.rb:379:in `method_missing'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/base.rb:2143:in`with_scope'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/association_proxy.rb:206:in `send'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/association_proxy.rb:206:in`with_scope'
    from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.3/lib/active_record/associations/association_collection.rb:375:in `method_missing'
    from /xxx/app/models/package.rb:43:in`parent_packages'
    from /xxx/app/models/package.rb:96:in `all_package_ids'
    from (irb):78:in`send'
    from (irb):78
    from :0>> 
# == Schema Information
# 
# Table name: packages_channels
# 
# channel_id :integer(4)
# package_id :integer(4)
# id         :integer(4)      not null, primary key
# 

class PackagesChannel < ActiveRecord::Base
  belongs_to :package
  belongs_to :channel

  # memcache indexes
  index :id
  index :package_id
  index [:package_id, :channel_id]

end

class Package < ActiveRecord::Base

 has_many :associated_packages

 def parent_packages
    # to make things mem_cache friendly (avoiding joins)
    associated_packages.all.collect{|assoc| assoc.associated_package}
 end

  def all_package_ids
    [self.id] + self.parent_packages.map{|pkg| pkg.all_package_ids}.flatten
  end

end
atif commented 14 years ago

Check if you have included "is_cached :repository => $cache" in more than one places. It should be included only at one place. Hope that helps!

dball commented 14 years ago

For what it's worth, I'm getting this too. It seems to happen on the second request to the cache which exercises a model loaded by foreign key and id, e.g index [:client_id, :id]

is_cached is definitely only appearing once

the repeating chunk of the stack is:

/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/accessor.rb:17:in `call'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/accessor.rb:17:in `fetch'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/accessor.rb:29:in `get'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:5:in `__send__'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:5:in `get'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:151:in `deserialize_objects'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:123:in `format_results'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:19:in `perform'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:7:in `perform'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/finders.rb:24:in `find_every'
/Users/dball/projects/deepsalt/source/serp/vendor/rails/activerecord/lib/active_record/base.rb:1583:in `find_one'
/Users/dball/projects/deepsalt/source/serp/vendor/rails/activerecord/lib/active_record/base.rb:1569:in `find_from_ids_without_cache'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:5:in `__send__'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:5:in `find_from_ids_without_cache'
/Users/dball/projects/deepsalt/source/serp/vendor/plugins/cache-money/lib/cash/query/abstract.rb:158:in `find_from_keys'
/Users/dball/projects/deepsalt/source/serp/vendor/rails/activesupport/lib/active_support/core_ext/module/delegation.rb:122:in `to_proc'