def is_message_duped(message):
    """
    Given a raw EMDR message string, determine whether we have already recently
    seen the same exact message.

    :rtype: bool
    :returns: ``True`` if this message is a duplicate, ``False`` if not.
    """
    global HASH_DEQUE

    # Generate a hash for the incoming message.
    message_hash = calc_hash_for_message(message)
    # Look at our queue of hashes to figure out if we've seen this
    # message yet.
    was_already_seen = message_hash in HASH_DEQUE
    # We always push the message on to the queue, even if it ends up being
    # a dupe, since it "refreshes" the hash.
    HASH_DEQUE.append(message_hash)

    return was_already_seen
def is_message_duped(message):
    """
    Given a raw EMDR message string, determine whether we have already recently
    seen the same exact message.

    :rtype: bool
    :returns: ``True`` if this message is a duplicate, ``False`` if not.
    """
    global HASH_DEQUE

    # Generate a hash for the incoming message.
    message_hash = calc_hash_for_message(message)
    # Look at our queue of hashes to figure out if we've seen this
    # message yet.
    was_already_seen = message_hash in HASH_DEQUE
    # We always push the message on to the queue, even if it ends up being
    # a dupe, since it "refreshes" the hash.
    HASH_DEQUE.append(message_hash)

    return was_already_seen
Beispiel #3
0
def is_message_duped(message):
    """
    Given a raw EMDR message string, determine whether we have already recently
    seen the same exact message.

    :rtype: bool
    :returns: ``True`` if this message is a duplicate, ``False`` if not.
    """
    global MC_CLIENT

    # Generate a hash for the incoming message.
    message_hash = str(calc_hash_for_message(message))
    cache_key = '%s%s' % (settings.RELAY_DEDUPE_STORE_KEY_PREFIX, message_hash)
    # Look at our queue of hashes to figure out if we've seen this
    # message yet.
    was_already_seen = MC_CLIENT.get(cache_key) is not None
    # We always push the message on to the queue, even if it ends up being
    # a dupe, since it "refreshes" the hash.
    MC_CLIENT.set(cache_key, 1, time=settings.RELAY_DEDUPE_STORE_TIME)

    return was_already_seen