Exemplo n.º 1
0
    def store_keys(cls, key, listing):
        """Look up query based on key, and update with provided listing.

        :param str key: key generated by :py:method:`make_key`
        :param list listing: sorted listing generated by
            `mr_reduce_max_per_key`, generally by :py:method:`write_permacache`
        """
        category, thing_cls, sort, time, uid = cls.split_key(key)

        query = None
        if category == "user":
            if thing_cls == "link":
                query = queries._get_submitted(int(uid), sort, time)
            elif thing_cls == "comment":
                query = queries._get_comments(int(uid), sort, time)
        elif category == "sr":
            if thing_cls == "link":
                query = queries._get_links(int(uid), sort, time)
        elif category == "domain":
            if thing_cls == "link":
                query = queries.get_domain_links(uid, sort, time)

        assert query, 'unknown query type for {}'.format(key)

        item_tuples = [(thing_fullname, float(value), float(timestamp))
                       for value, timestamp, thing_fullname in listing]
        # we only need locking updates for non-time-based listings, since for
        # time- based ones we're the only ones that ever update it
        lock = time == 'all'

        query._replace(item_tuples, lock=lock)
Exemplo n.º 2
0
    def store_keys(cls, key, listing):
        """Look up query based on key, and update with provided listing.

        :param str key: key generated by :py:method:`make_key`
        :param list listing: sorted listing generated by
            `mr_reduce_max_per_key`, generally by :py:method:`write_permacache`
        """
        category, thing_cls, sort, time, uid = cls.split_key(key)

        query = None
        if category == "user":
            if thing_cls == "link":
                query = queries._get_submitted(int(uid), sort, time)
            elif thing_cls == "comment":
                query = queries._get_comments(int(uid), sort, time)
        elif category == "sr":
            if thing_cls == "link":
                query = queries._get_links(int(uid), sort, time)
        elif category == "domain":
            if thing_cls == "link":
                query = queries.get_domain_links(uid, sort, time)

        assert query, 'unknown query type for {}'.format(key)

        item_tuples = [
            (thing_fullname, float(value), float(timestamp))
            for value, timestamp, thing_fullname in listing
        ]
        # we only need locking updates for non-time-based listings, since for
        # time- based ones we're the only ones that ever update it
        lock = time == 'all'

        query._replace(item_tuples, lock=lock)
Exemplo n.º 3
0
def store_keys(key, maxes):
    category, thing_cls, sort, time, id = key.split("/")

    query = None
    if category == "user":
        if thing_cls == "link":
            query = queries._get_submitted(int(id), sort, time)
        elif thing_cls == "comment":
            query = queries._get_comments(int(id), sort, time)
    elif category == "sr":
        if thing_cls == "link":
            query = queries._get_links(int(id), sort, time)
    elif category == "domain":
        if thing_cls == "link":
            query = queries.get_domain_links(id, sort, time)

    assert query, 'unknown query type for %s' % (key,)

    item_tuples = [tuple([item[-1]] + [float(x) for x in item[:-1]])
                   for item in maxes]

    # we only need locking updates for non-time-based listings, since for time-
    # based ones we're the only ones that ever update it
    lock = time == 'all'

    query._replace(item_tuples, lock=lock)
Exemplo n.º 4
0
def store_keys(key, maxes):
    category, thing_cls, sort, time, id = key.split("/")

    query = None
    if category == "user":
        if thing_cls == "link":
            query = queries._get_submitted(int(id), sort, time)
        elif thing_cls == "comment":
            query = queries._get_comments(int(id), sort, time)
    elif category == "sr":
        if thing_cls == "link":
            query = queries._get_links(int(id), sort, time)
    elif category == "domain":
        if thing_cls == "link":
            query = queries.get_domain_links(id, sort, time)
    assert query

    item_tuples = [tuple([item[-1]] + [float(x) for x in item[:-1]])
                   for item in maxes]
    query._replace(item_tuples)