[CDBI] Why does CDBI not populate the object on insert

Bill Moseley moseley at hank.org
Fri Mar 6 18:29:49 GMT 2009


On Thu, Mar 05, 2009 at 10:20:00PM -0800, Michael G Schwern wrote:
> > Is the lazy loading expensive when not used? That is where Essential
> > is tuned for the columns used?
> 
> Yes.  Rather than the getter just returning $obj->{$col} it has to check if
> its been loaded or not.  This might not seem like much, but if you have an app
> that calls accessor a lot it gets nasty.  And there's code like that all over,
> you can't just read from %{$obj->{cols}}.
> 
> Also, rather than just checking $obj->{is_loaded}{$col} it does quite a bit
> more work.  Look at how get() is implemented.
> 
> sub get {
>         my $self = shift;
>         return $self->_croak("Can't fetch data as class method") unless ref $self;
> 
>         my @cols = $self->_find_columns(@_);
>         return $self->_croak("Can't get() nothing!") unless @cols;
> 
>         if (my @fetch_cols = grep !$self->_attribute_exists($_), @cols) {
>                 $self->_flesh($self->__grouper->groups_for(@fetch_cols));
>         }
> 
>         return $self->_attrs(@cols);
> }
> 
> That could probably have some major optimization.  I'm not sure what the call
> to _find_columns() is about.  And $self->_attribute_exists($col) is nothing
> but exists $self->{$col}.

That code isn't that unreasonable.  Always room for optimizations, but
it's not too hard to throw more very fast servers at that kind of
problem these days.  Optimized/optional lazy loading and more specialized
methods for get() would probably be good, true.

It's the load on the database that is of most interest, so avoiding
"unnecessary" trips is good.

> > One of the reasons I still like CDBI is that it's a pretty
> > simple ORM, and when I need more complex joins (which is very common
> > in anything but the simplest application) I use set_sql().  I find SQL
> > a nice clean way to write database queries. ;)
> 
> Seek professional help.

That money is probably better spent on a good DBA. ;)

-- 
Bill Moseley.
moseley at hank.org
Sent from my iMutt



More information about the ClassDBI mailing list