So "group.forum.threads.posts.fetch(10)" is exactly the type of thing
you need to be cautious of.  That is actually doing a fetch to get the
forum, then another for threads, and lastly querying for ten posts.
That's a lot of datastore operations.

You might want to think about denormalizing your data structures so
that you can instad do something like:

   Posts.all().filter('group', group.key()).order('-timestamp')


Robert



On Fri, Jan 27, 2012 at 01:36, ikalbeniz <[email protected]> wrote:
> ok.. in my case i have something like this..
>
> class ForumGroup(db.Model):
>    name = db.StringProperty()
>    description = db.StringProperty(multiline=True)
>    created_at = db.DateTimeProperty(auto_now_add=True)
>
> class Forum(db.Model):
>    name = db.StringProperty()
>    description = db.StringProperty(multiline=True)
>    group = db.ReferenceProperty(ForumGroup,collection_name='forums')
>    created_at = db.DateTimeProperty(auto_now_add=True)
>
> Forum has a reference property group that references to ForumGroup so
> now ForumGroup object has a 'forums' property that is a Query
> object..
>
> i thought that when i got a ForumGroup doing get_by_id()
> simultaneously GAE made the query to get 'forums' object and so i got
> so many read quota..
>
> then i have other DB objects referenced so i can do
>
> group = ForumGroup().get_by_id(x)
>
> last_post_on_forum = group.forum.threads.posts.fetch(10)
>
>
>
> On 27 ene, 08:01, Robert Kluin <[email protected]> wrote:
>> Hi,
>>   When you access those reference properties they are fetched by key.
>> Unfortunately this will happen serially, which will significantly
>> impact your performance.  You're not going to avoid the read
>> operations without changing your schema, but you can at least improve
>> the performance by doing a batch fetch on all those referenced
>> entities.  One way to do this would look something like:
>>
>>   class SomeThing(db.Model):
>>     ref_prop = db.ReferenceProperty()
>>
>>     @property
>>     def ref_prop_key(self):
>>       return SomeThing.ref_prop.get_value_for_datastore(self)
>>
>>   thing = db.get(some_thing_key)
>>   other, entities = db.get([thing.ref_prop_key, thing.another_ref_prop_key])
>>
>>   This trick is to then *never* directly touch thing.ref_prop because
>> it will fetch the entity again.
>>
>> Robert
>>
>>
>>
>>
>>
>>
>>
>> On Thu, Jan 26, 2012 at 07:30, ikalbeniz <[email protected]> wrote:
>> > Hi,
>>
>> > I have developed a forum where i have structured the database using
>> > ReferenceProperties to link forum groups, forums, threads, posts and
>> > users.. so a group (db.model object) has N forums that have N threads
>> > with N posts..
>>
>> > I have a problem with the Datastore Read Operations Quota and i think
>> > than can be because when i get a Group object GAE gives me all tree
>> > structure so with one get_by_id i have lots of Datastore Read
>> > Operations..
>>
>> > Can someone confirm that this is ok? How an i avoid GAE do this so if
>> > i only want to show Group properties values so i dont need to acces
>> > all forums belongs to the group..
>>
>> > thanks.
>>
>> > --
>> > 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 
>> > athttp://groups.google.com/group/google-appengine?hl=en.
>
> --
> 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.
>

-- 
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