in reply to Re: Re: Battling with OOP performance
in thread Battling with OOP performance

Sounds like the real performance battle here is with the database. You should reconsider Class::DBI. It has a few solutions to this situation.

The first is lazy loading. You can have it query for all of the Persons attached to a Group, and it will create objects that just hold the ID. When you try to access another property on one of these, it does a query to load the other objects. This is good if you query for all of them, but only use the other properties of a few.

You could also just list the columns you want as essential columns on Person (i.e. always fetch these when getting a Person from the database) and then set up a "has_many" association from Group which automatically does the join and gets the essential columns all in one query.

Finally, if you need something special, you can add a custom SQL query to Person that finds all the information you want in one shot and Class::DBI handles all the work of creating the objects. It would look something like this:

package Person; ... __PACKAGE__->set_sql(by_group => q/ SELECT person_id, firstname, lastname FROM person WHERE group_id = ? /); package Group; ... sub get_members { my $self = shift; Person->search_by_group($self); }