[Lift] Re: Mapper: Is it possible to avoid the "n+1" selects?

2009-08-18 Thread Jeppe Nejsum Madsen

On Tue, Aug 18, 2009 at 7:46 PM, David
Pollak wrote:
>
>
> On Tue, Aug 18, 2009 at 12:32 AM, Jeppe Nejsum Madsen 
> wrote:
>>
>> On Thu, Aug 13, 2009 at 5:12 PM, Derek Chen-Becker
>> wrote:
>> > You should be able to use the PreCache QueryParam to tell Mapper to
>> > pre-fetch the mapped object:
>> >
>> >
>> > http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/PreCache.html
>>
>> Ok, time for a bonus question: Can this be extended to more than 1 level?
>
> You'd have to try it.  ;-)

Believe me, I tried :-) Couldn't really figure out what to use as
parameter and looking at dealWithPrecache it seems like the two tables
need to be directly linked

It's not super critial atm, so I'll get back to this if necessary

/Jeppe

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Mapper: Is it possible to avoid the "n+1" selects?

2009-08-18 Thread David Pollak
On Tue, Aug 18, 2009 at 12:32 AM, Jeppe Nejsum Madsen wrote:

>
> On Thu, Aug 13, 2009 at 5:12 PM, Derek Chen-Becker
> wrote:
> > You should be able to use the PreCache QueryParam to tell Mapper to
> > pre-fetch the mapped object:
> >
> >
> http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/PreCache.html
>
> Ok, time for a bonus question: Can this be extended to more than 1 level?


You'd have to try it.  ;-)

I don't think Mapper officially supports multiple levels of precaching.


>
>
> I have something similar to the following
>
> class Vehicle extends LongKeyedMapper[Vehicle] with IdPK {
>  object vehicleType extends MappedLongForeignKey(this, VehicleType)
> }
>
> class VehicleType extends LongKeyedMapper[VehicleType] with IdPK {
>  object brand extends MappedLongForeignKey(this, Brand)
> }
>
> class Brand extends LongKeyedMapper[Brand] with IdPK {
> }
>
> When displaying the list of vehicles I need to show both the vehicle,
> the vehicleType & the brand in the same table
>
> So to get the list of vehicles and caching the vehicletypes I do this:
>
>  override def findForListParams: List[QueryParam[Vehicle]] =
>  List(By(account, User.currentUser.open_!.account.is),
> PreCache(vehicleType))
>
> But I still get the n+1 selects when trying to resolve
> vehicleType.brand. Can this be remedied somehow?
>
> /Jeppe
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Mapper: Is it possible to avoid the "n+1" selects?

2009-08-18 Thread Derek Chen-Becker
I don't think it currently supports it, but I'd have to look at the source
to give a definitive answer.

On Tue, Aug 18, 2009 at 1:32 AM, Jeppe Nejsum Madsen wrote:

>
> On Thu, Aug 13, 2009 at 5:12 PM, Derek Chen-Becker
> wrote:
> > You should be able to use the PreCache QueryParam to tell Mapper to
> > pre-fetch the mapped object:
> >
> >
> http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/PreCache.html
>
> Ok, time for a bonus question: Can this be extended to more than 1 level?
>
> I have something similar to the following
>
> class Vehicle extends LongKeyedMapper[Vehicle] with IdPK {
>  object vehicleType extends MappedLongForeignKey(this, VehicleType)
> }
>
> class VehicleType extends LongKeyedMapper[VehicleType] with IdPK {
>  object brand extends MappedLongForeignKey(this, Brand)
> }
>
> class Brand extends LongKeyedMapper[Brand] with IdPK {
> }
>
> When displaying the list of vehicles I need to show both the vehicle,
> the vehicleType & the brand in the same table
>
> So to get the list of vehicles and caching the vehicletypes I do this:
>
>  override def findForListParams: List[QueryParam[Vehicle]] =
>  List(By(account, User.currentUser.open_!.account.is),
> PreCache(vehicleType))
>
> But I still get the n+1 selects when trying to resolve
> vehicleType.brand. Can this be remedied somehow?
>
> /Jeppe
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Mapper: Is it possible to avoid the "n+1" selects?

2009-08-18 Thread Jeppe Nejsum Madsen

On Thu, Aug 13, 2009 at 5:12 PM, Derek Chen-Becker wrote:
> You should be able to use the PreCache QueryParam to tell Mapper to
> pre-fetch the mapped object:
>
> http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/PreCache.html

Ok, time for a bonus question: Can this be extended to more than 1 level?

I have something similar to the following

class Vehicle extends LongKeyedMapper[Vehicle] with IdPK {
  object vehicleType extends MappedLongForeignKey(this, VehicleType)
}

class VehicleType extends LongKeyedMapper[VehicleType] with IdPK {
  object brand extends MappedLongForeignKey(this, Brand)
}

class Brand extends LongKeyedMapper[Brand] with IdPK {
}

When displaying the list of vehicles I need to show both the vehicle,
the vehicleType & the brand in the same table

So to get the list of vehicles and caching the vehicletypes I do this:

 override def findForListParams: List[QueryParam[Vehicle]] =
  List(By(account, User.currentUser.open_!.account.is),
PreCache(vehicleType))

But I still get the n+1 selects when trying to resolve
vehicleType.brand. Can this be remedied somehow?

/Jeppe

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Mapper: Is it possible to avoid the "n+1" selects?

2009-08-13 Thread Jeppe Nejsum Madsen

Derek Chen-Becker  writes:

> You should be able to use the PreCache QueryParam to tell Mapper to
> pre-fetch the mapped object:
>
> http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/PreCache.html

Ahh nice. I missed that one, Thanks

/Jeppe

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: Mapper: Is it possible to avoid the "n+1" selects?

2009-08-13 Thread Derek Chen-Becker
You should be able to use the PreCache QueryParam to tell Mapper to
pre-fetch the mapped object:

http://scala-tools.org/scaladocs/liftweb/1.0/net/liftweb/mapper/PreCache.html

Derek

On Thu, Aug 13, 2009 at 6:11 AM, Jeppe Nejsum Madsen wrote:

>
> Hi
>
> I have a mapped object A  with a foreign key to mapped object B.
>
> I need to display the information (A+B) in a table. The not so smart way
> is to first query on the As and then for each A, get the B. This
> results in n+1 selects.
>
> Is it possible to ask Mapper, when querying for the As, that it should
> join with Bs table to fetch the B at the same time (ie the equivalent of
> join fetching in Hibernate)?
>
> /Jeppe
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---