示例#1
0
def mass_insert_and_recurse(list_of_messages, recursion_level=0):
    for qaiku_message in list_of_messages:
        if not storage.in_cache(qaiku_message):
            storage.update(qaiku_message)
    # And then handle the recursions
    for qaiku_message in list_of_messages:
        recursive_fetch_message(qaiku_message['id'], recursion_level)
示例#2
0
def mass_insert_and_recurse(list_of_messages, recursion_level = 0):
    for qaiku_message in list_of_messages:
        if not storage.in_cache(qaiku_message):
            storage.update(qaiku_message)
    # And then handle the recursions
    for qaiku_message in list_of_messages:
        recursive_fetch_message(qaiku_message['id'], recursion_level)
示例#3
0
def fetch_replies(object_id, recursion_level = 0):
    """Get full list of replies to a message (and insert them to cache, recursing)"""
    object_id = str(object_id) # normalize the id
    if replycache.has_key(object_id):
        return replycache[object_id]
    replies = fetch_paged("http://www.qaiku.com/api/statuses/replies/%s.json" % object_id)
    if not replies:
        replies = []
    # Cache all the messages while at it
    mass_insert_and_recurse(replies, recursion_level)
    replycache[object_id] = map(lambda o: fetch_message(str(o['id'])), replies) # refresh the objects before placing them as pointers to the replycache
    # And put a list of the replies to the object we fetched them for
    obj = fetch_message(object_id)
    if storage.in_cache(obj): # this should not fail, not at this point anymore
        obj['QaikuBackup_replies'] = [ o['id'] for o in replies ] # Map a list of the reply IDs to the object (using python pointers we could just point to the list of objects but that would cause no end of headache for the JSON serialization we plane to do)
        # Force objectcache update to make sure we don't have funky COW issues
        storage.update(obj)
    return replycache[object_id]
示例#4
0
def fetch_replies(object_id, recursion_level=0):
    """Get full list of replies to a message (and insert them to cache, recursing)"""
    object_id = str(object_id)  # normalize the id
    if replycache.has_key(object_id):
        return replycache[object_id]
    replies = fetch_paged("http://www.qaiku.com/api/statuses/replies/%s.json" %
                          object_id)
    if not replies:
        replies = []
    # Cache all the messages while at it
    mass_insert_and_recurse(replies, recursion_level)
    replycache[object_id] = map(
        lambda o: fetch_message(str(o['id'])), replies
    )  # refresh the objects before placing them as pointers to the replycache
    # And put a list of the replies to the object we fetched them for
    obj = fetch_message(object_id)
    if storage.in_cache(
            obj):  # this should not fail, not at this point anymore
        obj['QaikuBackup_replies'] = [
            o['id'] for o in replies
        ]  # Map a list of the reply IDs to the object (using python pointers we could just point to the list of objects but that would cause no end of headache for the JSON serialization we plane to do)
        # Force objectcache update to make sure we don't have funky COW issues
        storage.update(obj)
    return replycache[object_id]
示例#5
0
def insert_and_recurse(qaiku_message, recursion_level=0):
    """Insert a message to cache and get all it's resources/replies/etc"""
    if not storage.in_cache(qaiku_message):
        storage.update(qaiku_message)
    return recursive_fetch_message(qaiku_message['id'], recursion_level)
示例#6
0
def insert_and_recurse(qaiku_message, recursion_level = 0):
    """Insert a message to cache and get all it's resources/replies/etc"""
    if not storage.in_cache(qaiku_message):
        storage.update(qaiku_message)
    return recursive_fetch_message(qaiku_message['id'], recursion_level)