0

我需要能够更快地搜索我的用户。没有 memcache 的搜索需要 8 秒。现在我的代码在Not Dot Net的帮助下使用了 memcache,这将搜索时间减少到 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方式,创建数据较少的表。只是用户名和元数据密钥
  • 新的全文搜索
  • 3rd 方开发人员的旧可搜索模型
  • Memcache 只需要属性并遍历它而不是一切

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

4

1 回答 1

3

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

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? .

于 2012-08-22T18:16:17.360 回答