[Catalyst] $c->user->some_relationship always retrives user id from the db

Matt S Trout dbix-class at trout.me.uk
Thu Feb 14 14:12:12 GMT 2008


On Thu, Feb 14, 2008 at 09:14:04AM +0100, Moritz Onken wrote:
> 
> Am 14.02.2008 um 00:11 schrieb Jay K:
> 
> >Hi there Moritz,
> >
> >The select by id that you are seeing is the retrieval of the user from
> >the database when first recovering the user from the session.  I am
> >assuming that you are using the
> >Catalyst::Authentication::Store::DBIx::Class storage module.   Any
> >access to $c->user will trigger this query.  It is, however, only done
> >once per request.
> >
> >In short - if you are going to be using $c->user in any way during the
> >request, that find by id will be done at some point.  So going out of
> >your way to avoid it only makes sense if you are sure you will not use
> >any other user information during the request.
> >
> >Jay
> 
> So why do I need to recovery the whole user row for every request?
> I could use
> $user_id = $c->session->{user_id};
> @albums = $c->model('albums')->search({ user_id => $user_id });
> as Mitchell suggested but I'd prefer to fetch the data by using $c- 
> >user because its the way one should do it.
> 
> might it be possible to store the user row in the session at login and  
> recover $c->user from the session on every request?
> I know this might break if I change something in the user row.

Or you could simply not load the row object until they request something
other than the id.

Both those behaviours and the current one could be useful, so I guess it'd
be a config option.

I'm betting the reason they currently don't exist is basically "because
nobody wrote a patch for it yet".

Who fancies volunteering?

-- 
      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list