Storing ResultSets in the schema

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Storing ResultSets in the schema

Tobias Kremer
On server startup I'd like to fetch the complete data of one table and store it
somewhere to allow faster retrieval of it later on. For this, I have added an
attribute to my DBIC schema class which is set during server startup with the
result of my ResultSet->search operation.

Basically the data stored in the schema is generated in a custom ResultSet class
with this:

  $data->{ $_->code } = $_ for $self->search->all;

The $data hashref is then stored in $schema during the start of MyApp with:

  $schema->foo_data( $data );  # foo_data being my custom attribute

Later on, I can access the data hashref with:

  $schema->get_foo_by_key( $key )

and get back the ResultSet preloaded during server start corresponding to $key.

Now, I'm wondering if storing complete ResultSets in the schema might be a bad
thing? I'm especially worried about creating memory leaks and/or circular
references.

Thanks!

--Tobias

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Storing ResultSets in the schema

Ash Berlin

On 7 Jul 2008, at 09:13, Tobias Kremer wrote:

> On server startup I'd like to fetch the complete data of one table  
> and store it
> somewhere to allow faster retrieval of it later on. For this, I have  
> added an
> attribute to my DBIC schema class which is set during server startup  
> with the
> result of my ResultSet->search operation.
>
> Basically the data stored in the schema is generated in a custom  
> ResultSet class
> with this:
>
>  $data->{ $_->code } = $_ for $self->search->all;
>
> The $data hashref is then stored in $schema during the start of  
> MyApp with:
>
>  $schema->foo_data( $data );  # foo_data being my custom attribute
>
> Later on, I can access the data hashref with:
>
>  $schema->get_foo_by_key( $key )
>
> and get back the ResultSet preloaded during server start  
> corresponding to $key.
>
> Now, I'm wondering if storing complete ResultSets in the schema  
> might be a bad
> thing? I'm especially worried about creating memory leaks and/or  
> circular
> references.
>
> Thanks!
>
> --Tobias

Yes, that would create a memory leak due to circular reference. You  
want Scalar::Util::weaken.

-ash


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

RE: Storing ResultSets in the schema

Alexander Hartmaier
I'd like to see a feature in dbic for this too.
I have some small tables where prefetching them slows down the queries quite a lot.
I load them on cat app startup, transform them to hashrefs and cache them for an hour with the caching plugin.
Something in dbic which transparently allows calling relationships without a db roundtrip would be great!

-Alex


-----Original Message-----
From: Ash Berlin [mailto:[hidden email]]
Sent: Monday, July 07, 2008 11:13 AM
To: DBIx::Class user and developer list
Subject: Re: [Dbix-class] Storing ResultSets in the schema


On 7 Jul 2008, at 09:13, Tobias Kremer wrote:

> On server startup I'd like to fetch the complete data of one table
> and store it
> somewhere to allow faster retrieval of it later on. For this, I have
> added an
> attribute to my DBIC schema class which is set during server startup
> with the
> result of my ResultSet->search operation.
>
> Basically the data stored in the schema is generated in a custom
> ResultSet class
> with this:
>
>  $data->{ $_->code } = $_ for $self->search->all;
>
> The $data hashref is then stored in $schema during the start of
> MyApp with:
>
>  $schema->foo_data( $data );  # foo_data being my custom attribute
>
> Later on, I can access the data hashref with:
>
>  $schema->get_foo_by_key( $key )
>
> and get back the ResultSet preloaded during server start
> corresponding to $key.
>
> Now, I'm wondering if storing complete ResultSets in the schema
> might be a bad
> thing? I'm especially worried about creating memory leaks and/or
> circular
> references.
>
> Thanks!
>
> --Tobias

Yes, that would create a memory leak due to circular reference. You
want Scalar::Util::weaken.

-ash


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...