本文整理汇总了Python中r2.models.last_modified.LastModified.get_multi方法的典型用法代码示例。如果您正苦于以下问题:Python LastModified.get_multi方法的具体用法?Python LastModified.get_multi怎么用?Python LastModified.get_multi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.last_modified.LastModified
的用法示例。
在下文中一共展示了LastModified.get_multi方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fast_query
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import get_multi [as 别名]
def _fast_query(cls, thing1s, thing2s, properties = None, **kw):
"""Find all of the relations of this class between all of the
members of thing1_ids and thing2_ids"""
thing1s, thing1s_is_single = tup(thing1s, True)
thing2s, thing2s_is_single = tup(thing2s, True)
if not thing1s or not thing2s:
return {}
# grab the last time each thing1 modified this relation class so we can
# know which relations not to even bother looking up
if thing1s:
from r2.models.last_modified import LastModified
fullnames = [cls._thing1_cls._fullname_from_id36(thing1._id36)
for thing1 in thing1s]
timestamps = LastModified.get_multi(fullnames,
cls._cf.column_family)
# build up a list of ids to look up, throwing out the ones that the
# timestamp fetched above indicates are pointless
ids = set()
thing1_ids, thing2_ids = {}, {}
for thing1 in thing1s:
last_modification = timestamps.get(thing1._fullname)
if not last_modification:
continue
for thing2 in thing2s:
key = cls._rowkey(thing1._id36, thing2._id36)
if key in ids:
continue
if thing2._date > last_modification:
continue
ids.add(key)
thing2_ids[thing2._id36] = thing2
thing1_ids[thing1._id36] = thing1
# all relations must load these properties, even if unrequested
if properties is not None:
properties = set(properties)
properties.add('thing1_id')
properties.add('thing2_id')
rels = {}
if ids:
rels = cls._byID(ids, properties=properties).values()
if thing1s_is_single and thing2s_is_single:
if rels:
assert len(rels) == 1
return rels[0]
else:
raise NotFound("<%s %r>" % (cls.__name__,
cls._rowkey(thing1s[0]._id36,
thing2s[0]._id36)))
return dict(((thing1_ids[rel.thing1_id], thing2_ids[rel.thing2_id]), rel)
for rel in rels)