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 9124329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:32:50+00:00 2026-06-17T06:32:50+00:00

I am trying to improve efficiency of my current query from appengine datastore. Currently,

  • 0

I am trying to improve efficiency of my current query from appengine datastore. Currently, I am using a synchronous method:

class Hospital(ndb.Model):
      name = ndb.StringProperty()
      buildings= ndb.KeyProperty(kind=Building,repeated=True)
class Building(ndb.Model):
      name = ndb.StringProperty()
      rooms= ndb.KeyProperty(kind=Room,repeated=True)
class Room(ndb.Model):
      name = ndb.StringProperty()
      beds = ndb.KeyProperty(kind=Bed,repeated=True)
class Bed(ndb.Model):
      name = ndb.StringProperty()
      .....

Currently I go through stupidly:

currhosp = ndb.Key(urlsafe=valid_hosp_key).get()
nbuilds = ndb.get_multi(currhosp.buildings)
for b in nbuilds:
   rms = ndb.get_multi(b.rooms)
   for r in rms:
      bds = ndb.get_multi(r.beds)
      for b in bds:
          do something with b object

I would like to transform this into a much faster query using get_multi_async

My difficulty is in how I can do this?
Any ideas?

Best
Jon

  • 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-17T06:32:51+00:00Added an answer on June 17, 2026 at 6:32 am

    using the given structures above, it is possible, and was confirmed that you can solve this with a set of tasklets. It is a SIGNIFICANT speed up over the iterative method.

    @ndb.tasklet
    def get_bed_info(bed_key):
        bed_info = {}
        bed = yield bed_key.get_async()
        format and store bed information into bed_info
        raise ndb.Return(bed_info)
    
    @nbd.tasklet
    def get_room_info(room_key):
        room_info = {}
        room = yield room_key.get_async()
        beds = yield map(get_bed_info,room.beds)
        store room info in room_info
        room_info["beds"] = beds
        raise ndb.Return(room_info)
    
    @ndb.tasklet
    def get_building_info(build_key):
        build_info = {}
        building = yield build_key.get_async()
        rooms = yield map(get_room_info,building.rooms)
        store building info in build_info
        build_info["rooms"] = rooms
        raise ndb.Return(build_info)
    
    @ndb.toplevel
    def get_hospital_buildings(hospital_object):
        buildings = yield map(get_building_info,hospital_object.buildings)
        raise ndb.Return(buildings)
    

    Now comes the main call from the hospital function where you have the hospital object (hosp).

    hosp_info = {}
    buildings = get_hospital_buildings(hospital_obj)
    store hospital info in hosp_info
    hosp_info["buildings"] = buildings
    return hosp_info
    

    There you go! It is incredibly efficient and lets the schedule complete all the information in the fastest possible manner within the GAE backbone.

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

Sidebar

Related Questions

I am currently trying to improve website loading times and I am using the
I've been trying to improve my password hashing class for a CMS I'm currently
I am coding for various programming olympiads and am trying to improve time efficiency.
I've been trying to improve the build times for my product. We're using continuous
I'm trying to improve my current algorithm for the 8 Queens problem, and this
I am trying to improve my SQL query so that i could get only
To improve my skills on Hector and cassandra I'm trying diffrent methods to query
Hey! I've finally started feeling comfortable using jQuery, so now I'm trying to improve
In trying to improve the speed of an immensely slow query (several minutes on
I'm trying to improve the performance on a query that is running very slowly.

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.