Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7867999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:51:46+00:00 2026-06-03T00:51:46+00:00

I have a latency problem in my application due to the datastore doing additional

  • 0

I have a latency problem in my application due to the datastore doing additional queries for referenced entities. I have received good advice on how to handle this for single value properties by the use of the get_value_for_datastore() function. However my application also have one-to many relationships as shown in the code below, and I have not found a way to prefetch these entities. The result is an unacceptable latency when trying to show a table of 200 documents and their associated documentFiles (>6000ms).

(There will probably never be more than 10.000 Documents or DocumentFiles)

Is there a way to solve this?

models.py

class Document(db.Expando):
    title = db.StringProperty()
    lastEditedBy = db.ReferenceProperty(DocUser, collection_name = 'documentLastEditedBy')  
...

class DocUser(db.Model):
    user = db.UserProperty()
    name = db.StringProperty()  
    hasWriteAccess= db.BooleanProperty(default = False)
    isAdmin = db.BooleanProperty(default = False)
    accessGroups = db.ListProperty(db.Key)
...

class DocumentFile(db.Model):
    description= db.StringProperty()
    blob = blobstore.BlobReferenceProperty()
    created = db.DateTimeProperty() # needs to be stored here in relation to upload / download of everything    
    document = db.ReferenceProperty(Document, collection_name = 'files')

    @property
    def link(self):     
        return '<a href="/file/serve/%s">%s</a>' % (self.key().id(),self.blob.filename) 
...

main.py

docUsers = DocUser.all()
docUsersNameDict = dict([(i.key(), i.name) for i in docUsers])

documents = Document.all()
for d idocuments:        
    out += '<td>%s</td>' % d.title    
    docUserKey = Document.lastEditedBy.get_value_for_datastore(d)
    out +='<td>%s</td>' % docUsersNameDict.get(docUserKey)
    out += '<td>'                           
    # Creates a new query for each document, resulting in unacceptable latency
    for file in d.files: 
        out +=  file.link + '<br>'
    out += '</td>'  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:51:49+00:00Added an answer on June 3, 2026 at 12:51 am

    Denormalize and store the link in your Document, so that getting the link will be fast.

    You will need to be careful that when you update a DocumentFile, you need to update the associated Document. This operates under the assumption that you read the link from the datastore far more often than you update it.

    Denormalizing is often the fix for poor performance on App Engine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing some performance tuning and capacity planning for a low-latency application and have
I'm porting a Windows application to Linux and I have a synchronization problem. In
Hi all I am not sure how to approach this problem. I have a
We use SharpSVN to programmatically access SVN repositories. Now we have the problem that
We have a typical business application with an Outlook-looking Winforms client talking to asmx
I have a problem with MPMoviePlayerController.When I am watching a video, and hit the
Does anyone have any good resources that show creating an unlimited number of threads
We have several latency-sensitive pipeline-style programs that have a measurable performance degredation when run
I'm trying to get a list of entities from a WCF service, the problem
I have a problem where I don't receive notifications every time I push them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.