Beispiel #1
0
def _populate_video_counters(videos):
    if not isinstance(videos, types.ListType):
        videos = [videos]
    counters = []
    cnt_to_video = {}
    for video in videos:
        counters_map = VideoModels.counters_map(video)
        for (k, v) in counters_map.iteritems():
            counters.append(k)
            cnt_to_video[k] = video
    results = fastcounter.get_counts(counters)
    for i in xrange(0, len(counters)):
        cntr = counters[i]
        video = cnt_to_video[cntr]
        counters_map = VideoModels.counters_map(video)
        video[counters_map[cntr]] = results[i]
Beispiel #2
0
def _populate_comment_counters(channel_id, video_id, tree):
    counters = []
    like_ctr_to_node = {}
    dislike_ctr_to_node = {}
    for comment in tree.comments():
        like_ctr = comment_like_counter(channel_id, video_id, comment["i"])
        dislike_ctr = comment_dislike_counter(channel_id, video_id, comment["i"])
        counters.extend([like_ctr, dislike_ctr])
        like_ctr_to_node[like_ctr] = comment
        dislike_ctr_to_node[dislike_ctr] = comment
    results = fastcounter.get_counts(counters)
    for i in xrange(0, len(counters)):
        if like_ctr_to_node.has_key(counters[i]):
            node = like_ctr_to_node[counters[i]]
            node["l"] = results[i]
        else:
            node = dislike_ctr_to_node[counters[i]]
            node["d"] = results[i]