[Dbix-class] Loading ResultSource's abit like a trait

fREW Schmidt frioux at gmail.com
Tue Nov 9 15:27:00 GMT 2010


On Mon, Nov 8, 2010 at 3:03 AM, Benjamin Martin <
benjamin.martin at ims-evolve.com> wrote:

> Hello all,
>
> I have a dbix::class schema with quite a few resultsource files.
>
> The schema is used by a few different apps.
>
> Typically only a few a of the resultsource files need to be loaded as the
> app using the schema is only touching a few tables.. but in other
> applications alot more of the resultsource files are needed.
>
> The start up time and mem foot print is alot larger than it could be for
> the apps only using part of the schema .. so ...
>
> My question is, is there is a way to instanciate a schema but only loading
> a few of the resultsource files?
>
> I was thinking perhaps I could do something that loads resultsource files
> simlar to traits but am not sure if this is advisable or if there is alre=
ady
> something that does this?
>
> Many thanks for any comments/advise/links you have that might help.
>
> Cheers,
> -Ben
>
>
We had a similar situation where we have something like 600 tables for a
bunch of reporting tables, so we just load those on demand.  This is how we
did it (a method in our schema):

sub load_report {
   my $self =3D shift;
   my $report_num =3D shift or die 'report_num is required for load_report';
   return if (first { $_ eq "Rpt$report_num" } $self->sources); # don't load
again if it's loaded already
   eval "require MyApp::Schema::NonDefaultResult::rpt_$report_num";
   $self->register_class("Rpt$report_num",
"MyApp::Schema::NonDefaultResult::rpt_$report_num");
   return $self;
}

Note that if you are doing this for *all* of your resultsets you might as
well just override the resultset method itself and have it load the other
classes lazily.

Also note that I put things in NonDefaultResult; that's because we are using
"load_namespaces()".  If you really do want to load all of your classes
lazily I recommend *not* doing load_namespaces and putting the classes in
the "standard" location.


-- =

fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101109/923=
86490/attachment-0001.htm


More information about the DBIx-Class mailing list