【问题标题】:How can I make my App Engine Datastore user search faster?如何让我的 App Engine Datastore 用户搜索更快?
【发布时间】:2012-08-18 04:26:02
【问题描述】:

我需要能够更快地搜索我的用户。没有 memcache 的搜索需要 8 秒。现在我的代码在Not Dot Net 的帮助下利用了内存缓存,这将搜索时间减少到了 4 秒。我现在的问题是,我怎样才能让它更快?

qUserSearch = Utilities.deserialize_entities(memcache.get("qUserSearch"))
if not qUserSearch:
    qUserSearch = db.GqlQuery("SELECT * FROM User ORDER BY created DESC").fetch(100000)
    memcache.add("qUserSearch", Utilities.serialize_entities(qUserSearch))

searchLength = len(searchData) 
hits = []
gotHits = False

for u in qUserSearch:
    searchEmail = u.email[0:searchLength]
    if searchEmail == searchData:
        hits.append( u.key() )
    else:
        # Since I only search for the first x chars
        # will there never be hits after it's had hits
        if gotHits:
            break 
return hits

我的第一个想法:

  • 仅转换为 ndb 和 SELECT,需要,来自用户的数据
  • SQL方式,创建数据较少的表。只是用户名和元数据密钥
  • 新的全文搜索
  • 第 3 方开发人员可搜索的旧模型
  • Memcache 只需要属性并遍历它而不是所有东西

或者你有其他想法吗?你认为哪一次我会节省最多的时间?

【问题讨论】:

    标签: google-app-engine memcached python-2.7 python-memcached


    【解决方案1】:

    您还可以使用两个不等式过滤器模拟您尝试完成的前缀搜索

    db.GqlQuery("SELECT * FROM User WHERE email >= :1 AND email <= :2", searchData, unicode(searchData) + u"\ufffd")
    

    注意:此答案取自为问题 Google App Engine: Is it possible to do a Gql LIKE query? 提供的第二个答案。

    【讨论】:

    • 23 毫秒比 4325 毫秒要好得多。谢谢!并感谢来源
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 2017-04-13
    • 1970-01-01
    • 2010-11-03
    相关资源
    最近更新 更多