DeadlineExceededError

时间:2011-04-26 03:16:00

标签: google-app-engine gqlquery

当我尝试在Google App Engine的数据存储区中使用这样的查询时:

user = User.all().filter('name =',userName).get()

我有这个错误:DeadlineExceededError

修改 这是我的功能:

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 request.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))

搜索Feed时,需要花费太多时间,提高DeadlineExceededError

1 个答案:

答案 0 :(得分:1)

这不会缩放:

    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)

您将每个Feed对象从数据存储中拉回来,然后根据搜索词本地过滤列表。如果您只想在每页显示10条记录,请在查询对象上执行fetch(10),这样您就不会尝试撤回一个页面中的每个实体。使用query cursors进行分页。如果要过滤大量实体,则需要预先定义满足查询的数据存储索引;获取所有内容并在本地过滤是非常低效的。