[Dbix-class] Lazy loading of attributes?

Matt S Trout dbix-class at trout.me.uk
Fri Nov 11 19:29:44 CET 2005


On Fri, Nov 11, 2005 at 12:25:19AM +0100, Jesper Krogh wrote:
> Jules Bean wrote:
> >>I have a table with some quite large attributes that only should be
> >>fetched when they are accessed. In Class::DBI this was done by the
> >>"columns(Other => qw(att1 att2)) but that seems to fail in DBIx::Class
> >>
> >>How is this typically done in DBIx::Class?
> >
> >The defaulting to lazy attributes was responsible for a lot of poor 
> >performance. I imagine that's why DBIC doesn't default the same way. 
> >(It's far better to make one big query than 1000 small ones).
> 
> I can understand that...
> 
> >Unfortunately I don't believe there's a way of setting some attributes 
> >to 'dont select by default', but what you can do is add the cols 
> >attribute to your searches, as in 
> >->search({name=>"Jesper"},{cols=>qw/phone address email/}).
> 
> .. but I have a single attribute that contributes 230KB binary data, 
> that I really would like to not load by default and only load when 
> nessesary. This doesn't seem like an uncommon use-case to me.
> 
> So I really belive that the system should default to load all attributes 
> (since the normal overhead is very low) and having an option to deselect 
> automatically loading of specific attributes.

There's the beginning of such a system in the form of _select_columns -

$attrs->{cols} ||= [ map { "me.$_" } $db_class->_select_columns ];

(from DBIx::Class::ResultSet)

- but it's a bit primitive and we still don't have the capacity to go
back to the database automatically for the extra columns (outside of
CDBICompat::LazyLoading which does fine but relies on column groups).

Give it a go, but please bear in mind the API isn't an official one and
will vanish as soon as we get something better :)

-- 
     Matt S Trout       Specialists in Perl consulting, web development, and
  Technical Director    UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Dbix-class mailing list