Hi Carter,

Querying on one property or another has effectively no difference in
performance. There are other considerations, however:
- Using a key will allow you to potentially add support for users
authenticated in other ways (Eg, an external authentication framework)
without changing the rest of your models.
- If you set the key_name of the userinfo model to the user_id of the user,
you don't need to look the record up - you can create its key based on the
logged in user with no datastore operations
- Querying on user objects can be tricky, particularly if the user has
changed their email address. It's best to avoid doing this if you can.

-Nick Johnson

On Fri, Jun 17, 2011 at 6:16 AM, Carter <[email protected]> wrote:

> Is a query on type User more expensive than querying on type Key?
>
> In storing references to users of your application across multiple
> Kinds, which is better the better approach assuming I don't need
> locking for transactions?
>
> a) store the "User" type (the actual User object) or
> b) store a "Key" type (that was used as the Primary Key for a Kind
> that stores user information)
>
> For example, if the Kind AppUser is defined as...
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class AppUser {
>        @PrimaryKey
>        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>        private Key key;
>
>        @Persistent
>        private User user;
> ...
> }
>
> and we're storing an image uploaded by that AppUser, is it better to
> use:
>
> Option (a)
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class UploadedImage {
>        @PrimaryKey
>        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>        private Key key;
>
>        @Persistent
>        private User user;
> ...
> }
>
> or, Option (b)
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class UploadedImage {
>        @PrimaryKey
>        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>        private Key key;
>
>        @Persistent
>        private Key appUserKey;
> ...
> }
>
> When retrieving 100s of images owned by the currentUser(), is option
> (b) preferred even though it would require the initial lookup of the
> AppUser  before querying UploadedImage using appUserKey?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>


-- 
Nick Johnson, Developer Programs Engineer, App Engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to