【发布时间】: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