Hi List, how do you think about storing the level of an entry into the database. For each entry you request item.level there now is a count * request to the database. In a huge set this can be a performance issue. At most applications you have much more reading then writing to a database, so this can improve performance. For backward compatibility this could be added via an option like class MyModel < ActiveRecord::Base acts_as_nested_set :level => :depth end Something similar it''s in acts_as_threaded or as a callback: def before_create # Update the child object with its parents attrs unless self[:parent_id].to_i.zero? self[:depth] = parent[:depth].to_i + 1 end end How do you think about this? Cheers, Matze
Jean-Christophe Michel
2007-Jan-06 16:25 UTC
[Betternestedset-talk] item.level store in db
Hi Matthias, Le 6 janv. 07, ? 12:45, Matthias Heigl a ?crit :> how do you think about storing the level of an entry into the database. > > For each entry you request item.level there now is a count * request > to the database. In a huge set this can be a performance issue. > > At most applications you have much more reading then writing to a > database, so this can improve performance. > ... > How do you think about this?Are you sure it''s not premature optimisation ? If you have benchmarks proving this is a weak point in betternestedset performances and your solution enhances them, I agree, go ahead. I would tend to think that db engine internal optimization can be quite as good as the one we can add in interpreted ruby layer... Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set