I have a database structure like this -
class Movie(db.Model):
name = db.StringProperty()
class Tag(db.Model):
name = db.StringProperty()
class MovieTag(db.Model):
movie = db.ReferenceProperty(Movie, collection_name='tags')
tag = db.ReferenceProperty(Tag, collection_name='movies')
I have a query where I am trying to retrieve all the movies with the tags. I have a query like this.
query = Movie.all()
movies = [{"name":movie.name,
"tags":[t.tag.name for t in movie.tags]} for movie in query]
However, this is taking very long time specially with a large number of movies (about 400). How do I optimize this? I have tried memcaching but the first call is still very slow and causes the 30s response timeout.