← Back to team overview

launchpad-dev team mailing list archive

Re: Generic Colletion?

 

On 2010-08-02 22:52, Jamu Kakar wrote:

The way we implement the pattern in Landscape is, I think, a bit
simpler.  We don't end up with a very general solution like you have
with the implementation in Launchpad, but we don't have that many
objects we want collections for, so it's not really a problem.
Anyway, the pattern we use is to store the primitive values needed
to construct the query.  When collection.with_computer_ids(ids) is
invoked we store 'ids', instead of creating a Computer.id.is_in(ids)
expression and storing that.  Each collection must implement a
_get_result method that uses the primitive data that has been
gathered to generate a query.
The idea with our Collection was that you can do this if you really want 
to, but it should be a distant second place to the simple, 
straightforward case.
The simple case does not require anything but a one-liner 
with_computer_ids implementation.  But you pay a higher price if you do 
want to optimize the SQL: you'd make with_computer_ids store the ids 
list, and override select to take the ids list into account somehow.  I 
think that's similar to the Landscape approach.

Jeroen



Follow ups

References