(key='traffic', timeout=300, minutes=60)
return traffic
Obtains the number of distinct IP numbers.
Obtains the number of distinct IP numbers.
Obtains the number of distinct IP numbers .
def get_traffic(key='traffic', timeout=300, minutes=60):
    """
    Obtains the number of distinct IP numbers.
    """
    traffic = cache.get(key)
    if not traffic:
        recent = util.now() - timedelta(minutes=minutes)
        try:
            traffic = models.PostView.objects.filter(date__gt=recent).distinct('ip').count()
        except NotSupportedError as exc:
            traffic = models.PostView.objects.filter(date__gt=recent).values_list('ip')
            traffic = [t[0] for t in traffic]
            traffic = len(set(traffic))
        # It is possible to not have hit any postview yet.
        traffic = traffic or 1
        cache.set(key, traffic, timeout)

    return traffic
def get_traffic ( key = 'traffic' , timeout = 300 , minutes = 60 ) : traffic = cache . get ( key ) if not traffic : recent = util . now ( ) - timedelta ( minutes = minutes ) try : traffic = models . PostView . objects . filter ( date__gt = recent ) . distinct ( 'ip' ) . count ( ) except NotSupportedError as exc : traffic = models . PostView . objects . filter ( date__gt = recent ) . values_list ( 'ip' ) traffic = [ t [ 0 ] for t in traffic ] traffic = len ( set ( traffic ) ) # It is possible to not have hit any postview yet. traffic = traffic or 1 cache . set ( key , traffic , timeout ) return traffic