From killerstorm at newmail.ru Thu Jun 17 22:19:06 2010 From: killerstorm at newmail.ru (Alex Mizrahi) Date: Fri, 18 Jun 2010 01:19:06 +0300 Subject: [elephant-devel] Persistent class slot References: Message-ID: > The issue I have is: I am using Weblocks + Elephant + Postmodern to > display the instances of a class in > paginated web pages. Weblocks needs to know the total count of the > instances to plan the pagination (so it > can display something like "1 of > xxx pages" ). It turns out just counting (by map-class) the instances > (about > 5000) will take about 8 seconds (my laptop is not that powerful, but quite > decent). I guess it would be faster with BDB, but it still needs to go through all records. > Counting instances of a class seems to be a very common use case. > So I hope the above is convincing enough for the need of persistent class > slots. > But I am too inexperienced to know how much work this will require. You can do that without persistent class slots -- make a counter class and update its value. Something like this: (defpclass counter () ((classname :index t :initarg :classname) (counter :initform 0))) Then you can increment it automatically: (defmethod initialize-instance ((foo bar) &key &allow-other-keys) (let ((counter (get-instance-from-value 'counter 'classname 'bar))) (incf (slot-value counter 'counter)))) It isn't pretty but it will work. Moreover, you need to implement this only once, so it doesn't matter how it is implemented. If we implement class slots, they will work in a similar way under the hood. From wrn.lynn at gmail.com Fri Jun 18 19:41:10 2010 From: wrn.lynn at gmail.com (Warren Lynn) Date: Fri, 18 Jun 2010 15:41:10 -0400 Subject: [elephant-devel] Persistent class slot In-Reply-To: References: Message-ID: > > You can do that without persistent class slots -- make a counter class and > update its value. > Something like this: > > (defpclass counter () > ((classname :index t :initarg :classname) > (counter :initform 0))) > > Then you can increment it automatically: > > (defmethod initialize-instance ((foo bar) &key &allow-other-keys) > (let ((counter (get-instance-from-value 'counter 'classname 'bar))) > (incf (slot-value counter 'counter)))) > > It isn't pretty but it will work. > Moreover, you need to implement this only once, so it doesn't matter how it > is implemented. > > If we implement class slots, they will work in a similar way under the > hood. > > > Thanks. This is a neat trick. BTW: for now I have dropped the use of Elephant for some reasons (my own compilation issues with BDB, BDB licence, performance, query power). But thank you and other Elephant developers very much for your help in my investigation of this framework. -------------- next part -------------- An HTML attachment was scrubbed... URL: