本文整理汇总了Python中r2.models.link.Comment._query方法的典型用法代码示例。如果您正苦于以下问题:Python Comment._query方法的具体用法?Python Comment._query怎么用?Python Comment._query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r2.models.link.Comment
的用法示例。
在下文中一共展示了Comment._query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from r2.models.link import Comment [as 别名]
# 或者: from r2.models.link.Comment import _query [as 别名]
def run():
STEP = 100
thing = Link
max_id = max_thing_id(thing)
id_start = 0
for id_low in xrange(id_start, max_id + 1, STEP):
print "Add desc karma for links %s to %s" % (id_low, id_low + STEP)
links = list(query_thing_id_range(thing, id_low, id_low + STEP))
for link in links:
if not link._loaded:
link._load()
comments = list(Comment._query(Comment.c.link_id == link._id, eager_load = True))
link_descendant_karma = 0
for comment in comments:
if not comment._loaded:
comment._load()
if hasattr(comment, 'parent_id') and comment.parent_id:
Comment._byID(comment.parent_id).incr_descendant_karma([], comment._ups - comment._downs)
link_descendant_karma += (comment._ups - comment._downs)
link._incr('_descendant_karma', link_descendant_karma)
示例2: rebuild
# 需要导入模块: from r2.models.link import Comment [as 别名]
# 或者: from r2.models.link.Comment import _query [as 别名]
def rebuild(cls, link):
# fetch all comments and sort by parent_id, so parents are added to the
# tree before their children
q = Comment._query(Comment.c.link_id == link._id,
Comment.c._deleted == (True, False),
Comment.c._spam == (True, False),
optimize_rules=True,
data=True)
comments = sorted(q, key=lambda c: c.parent_id)
# remove any comments with missing parents
comment_ids = {comment._id for comment in comments}
comments = [
comment for comment in comments
if not comment.parent_id or comment.parent_id in comment_ids
]
# build tree from scratch (for V2 results in double-counting in cass)
tree = cls(link, cids=[], tree={}, depth={}, parents={})
impl = cls.IMPLEMENTATIONS[link.comment_tree_version]
impl.rebuild(tree, comments)
link.num_comments = sum(1 for c in comments if not c._deleted)
link._commit()
return tree
示例3: _populate
# 需要导入模块: from r2.models.link import Comment [as 别名]
# 或者: from r2.models.link.Comment import _query [as 别名]
def _populate(after_id=None, estimate=54301242):
from r2.models import desc
from r2.lib.db import tdb_cassandra
from r2.lib import utils
# larger has a chance to decrease the number of Cassandra writes,
# but the probability is low
chunk_size = 5000
q = Comment._query(Comment.c._spam == (True, False), Comment.c._deleted == (True, False), sort=desc("_date"))
if after_id is not None:
q._after(Comment._byID(after_id))
q = utils.fetch_things2(q, chunk_size=chunk_size)
q = utils.progress(q, verbosity=chunk_size, estimate=estimate)
for chunk in utils.in_chunks(q, chunk_size):
chunk = filter(lambda x: hasattr(x, "link_id"), chunk)
update_comment_votes(chunk)
示例4: rebuild
# 需要导入模块: from r2.models.link import Comment [as 别名]
# 或者: from r2.models.link.Comment import _query [as 别名]
def rebuild(cls, link):
# retrieve all the comments for the link
q = Comment._query(
Comment.c.link_id == link._id,
Comment.c._deleted == (True, False),
Comment.c._spam == (True, False),
optimize_rules=True,
)
comments = list(q)
# remove any comments with missing parents
comment_ids = {comment._id for comment in comments}
comments = [
comment for comment in comments
if not comment.parent_id or comment.parent_id in comment_ids
]
CommentTreePermacache.rebuild(link, comments)
link.num_comments = sum(1 for c in comments if not c._deleted)
link._commit()