DeadlineExceededError
When I try to use a query in Google App Engine's datastore like this:
user = User.all().filter('name =',userName).get()
I have this error: DeadlineExceededError
.
EDIT: This is my function:
def feeds(request):
dict = get_user_details()
search_key = None
if request.GET.has_key('search_key'):
search_key = request.GET['search_key']
dict['search_key']=search_key
feeds = list()
if search_key is not None and search_key!="":
feeds_list = Feed.all().order('-CreatedDate')
search_string=string.upper(search_key)
for feed in feeds_list:
feed_name=string.upper(feed.FeedUrl)
if search_string in feed_name:
feeds.append(feed)
dict['search_key']=search_key
else:
feeds = Feed.all().order('-CreatedDate')
if requ开发者_运维技巧est.GET.has_key('page'):
page = request.GET['page']
try:
page = int(page) - 1
except:
page = 0
paginator = Paginator(feeds,10)
if page>=paginator._get_num_pages():
page = paginator._get_num_pages() - 1
dict["page_obj"] = paginator.page(page+1)
return render_to_response('feed_list.html', dict, context_instance=RequestContext(request))
Searching on Feeds, it takes too much time, raising a DeadlineExceededError
.
This won't scale:
feeds_list = Feed.all().order('-CreatedDate') search_string=string.upper(search_key) for feed in feeds_list: feed_name=string.upper(feed.FeedUrl) if search_string in feed_name: feeds.append(feed)
You're pulling every single Feed object back from the datastore and then locally filtering the list based on a search term. If you only want to show 10 records per page, do a fetch(10)
on your query object so you're not trying to pull back every entity in one page. Use query cursors for pagination. If you want to filter a large set of entities, you need to pre-define a datastore index that will satisfy the query; fetching everything and filtering locally is prohibitively inefficient.
精彩评论