本文整理汇总了Python中r2.models.last_modified.LastModified.get方法的典型用法代码示例。如果您正苦于以下问题:Python LastModified.get方法的具体用法?Python LastModified.get怎么用?Python LastModified.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.last_modified.LastModified
的用法示例。
在下文中一共展示了LastModified.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_last_visit
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import get [as 别名]
def update_last_visit(self, current_time):
from admintools import apply_updates
apply_updates(self)
prev_visit = LastModified.get(self._fullname, "Visit")
if prev_visit and current_time - prev_visit < timedelta(days=1):
return
g.log.debug("Updating last visit for %s from %s to %s" % (self.name, prev_visit, current_time))
LastModified.touch(self._fullname, "Visit")
示例2: update_last_visit
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import get [as 别名]
def update_last_visit(self, current_time):
from admintools import apply_updates
timer = g.stats.get_timer("account.update_last_visit")
timer.start()
apply_updates(self, timer)
prev_visit = LastModified.get(self._fullname, "Visit")
timer.intermediate("get_last_modified")
if prev_visit and current_time - prev_visit < timedelta(days=1):
timer.intermediate("set_last_modified.noop")
timer.stop()
return
LastModified.touch(self._fullname, "Visit")
timer.intermediate("set_last_modified.done")
timer.stop()
示例3: fast_query
# 需要导入模块: from r2.models.last_modified import LastModified [as 别名]
# 或者: from r2.models.last_modified.LastModified import get [as 别名]
def fast_query(cls, thing1, thing2s):
"""Find relationships between thing1 and various thing2s."""
thing2s, thing2s_is_single = tup(thing2s, ret_is_single=True)
if not thing1:
return {}
# don't bother looking up relationships for items that were created
# since the last time the thing1 created a relationship of this type
if cls._last_modified_name:
from r2.models.last_modified import LastModified
timestamp = LastModified.get(thing1._fullname,
cls._last_modified_name)
if timestamp:
thing2s = [thing2 for thing2 in thing2s
if thing2._date <= timestamp]
else:
thing2s = []
if not thing2s:
return {}
# fetch the row from cassandra. if it doesn't exist, thing1 has no
# relation of this type to any thing2!
try:
columns = [thing2._id36 for thing2 in thing2s]
results = cls._cf.get(thing1._id36, columns)
except NotFoundException:
results = {}
# return the data in the expected format
if not thing2s_is_single:
# {(thing1, thing2) : value}
thing2s_by_id = {thing2._id36 : thing2 for thing2 in thing2s}
return {(thing1, thing2s_by_id[k]) : v
for k, v in results.iteritems()}
else:
if results:
assert len(results) == 1
return results.values()[0]
else:
raise NotFound("<%s %r>" % (cls.__name__, (thing1._id36,
thing2._id36)))