[Dbix-class] Molesting Schemas

Matt S Trout dbix-class at trout.me.uk
Wed Jun 7 17:57:22 CEST 2006


Christopher H. Laco wrote:
> Matt S Trout wrote:
>   
>> Christopher H. Laco wrote:
>>     
>>> As part of the new Handel stuff, I'm trying to provide as much ability
>>> as possible of using an existing schema instead of just relying on the
>>> default Handel schema.
>>>
>>> As part of this process, I'm 'injecting' custom component classes into
>>> the specified schema using load_components. Currently, this operates on
>>> the classes themselves using $schema_class->class($cart_class).
>>>
>>> The evil in this is that fact that once I inject Handel components into
>>> the schema classes, they will effect the use of the schema outside of
>>> Handel. This is somewhat of a Bad Thing.
>>>
>>> So, my question is two fold: First, is it possible to load_component a
>>> new component into a source instance only, not its class, in a way that
>>> it will only effect the current source/schema instance, and not all
>>> usages of the source class?
>>>
>>> $schema_instance->source($cart_source)->load_components(qw/Foo/)
>>>
>>> where
>>>
>>> $schema_instance->class($cart_class) does not have "Foo" loaded?
>>>       
>> No, because this happens at the class level.
>>
>> OTOH you *could* quite happily take the user schema, compose_namespace
>> it to somewhere else (like e.g. Catalyst::Model::DBIC::Schema does) and
>> then inject stuff into the classes in the composed version, which will
>> have no effect whatsoever on the originals.
>>
>>
>>     
>
> This works, but it appears to cause quite the performance issue when
> calling load_components() on the new classes. The performance issue
> appears to go away if I call load_components either before
> compose_namespace, or on the schema class, and not on a connected schema
> object.
>
> Is there a better way to get at entires rows before update/insert calls,
> other than loading components into the result sources?
>   
The issue is load_components calling C3 re-init every time, which can be 
quite expensive. If you're making multiple load_components calls, do

Class::C3->uninitialize;
$Class::C3::TURN_OFF_C3 = 1;
<do all your component faffing here>
$Class::C3::TURN_OFF_C3 = 0;
Class::C3->reinitialize;

that way you'll only take the time hit once.



More information about the Dbix-class mailing list