Beispiel #1
0
def monitor(request, template='feedly/monitor.html'):
    context = RequestContext(request)
    #HACK for django <1.3 beta compatibility
    if 'STATIC_URL' not in context and 'MEDIA_URL' in context:
        context['STATIC_URL'] = context['MEDIA_URL']
    sample_size = int(request.GET.get('sample_size', 2))
    lucky_users = random.sample(xrange(10 ** 6), sample_size) + [13]
    users_dict = get_user_model().objects.get_cached_users(lucky_users)

    #retrieve all the counts in one pipelined request(s)
    count_dict = {}
    with get_redis_connection().map() as redis:
        for user_id in users_dict:
            feed = LoveFeed(user_id, redis=redis)
            count = feed.count()
            count_dict[user_id] = count

    for user_id, count in count_dict.items():
        profile = users_dict[user_id].get_profile()
        redis_count = int(count_dict[user_id])
        db_max = redis_count + 10
        db_count = profile._following_loves().count()
        print profile, db_count, long(redis_count)

    return render_to_response(template, context)
Beispiel #2
0
 def test_small_feed_instance(self):
     loves = Love.objects.all()[:5]
     feed = LoveFeed(13, max_length=2)
     for love in loves:
         activity = Activity(love.user, LoveVerb, love, love.user, time=love.created_at, extra_context=dict(hello='world'))
         feed.add(activity)
     self.assertEqual(feed.count(), feed.max_length)
Beispiel #3
0
def index(request, template='feedly/index.html'):
    context = RequestContext(request)
    #HACK for django <1.3 beta compatibility
    if 'STATIC_URL' not in context and 'MEDIA_URL' in context:
        context['STATIC_URL'] = context['MEDIA_URL']
    sample_size = int(request.GET.get('sample_size', 1000))
    context['sample_size'] = sample_size
    lucky_users = random.sample(xrange(10 ** 6), sample_size) + [13]
    users_dict = get_user_model().objects.get_cached_users(lucky_users)
    buckets = [0, 24, 1 * 24, 3 * 24, 10 * 24, 30 * 24, 50 * 24, 100 *
               24, 150 * 24, 1000 * 24]
    bucket_dict = dict([(b, 0) for b in buckets])
    count_dict = {}

    #retrieve all the counts in one pipelined request(s)
    with get_redis_connection().map() as redis:
        for user_id in users_dict:
            feed = LoveFeed(user_id, redis=redis)
            count = feed.count()
            count_dict[user_id] = count

    #divide into buckets using bisect left
    for user_id, count in count_dict.items():
        bucket_index = bisect.bisect_left(buckets, count)
        bucket = buckets[bucket_index]
        bucket_dict[bucket] += 1
    bucket_stats = bucket_dict.items()
    bucket_stats.sort(key=lambda x: x[0])
    context['bucket_stats'] = bucket_stats

    return render_to_response(template, context)
Beispiel #4
0
def monitor(request, template='feedly/monitor.html'):
    context = RequestContext(request)
    #HACK for django <1.3 beta compatibility
    if 'STATIC_URL' not in context and 'MEDIA_URL' in context:
        context['STATIC_URL'] = context['MEDIA_URL']
    sample_size = int(request.GET.get('sample_size', 2))
    lucky_users = random.sample(xrange(10**6), sample_size) + [13]
    users_dict = User.objects.get_cached_users(lucky_users)

    #retrieve all the counts in one pipelined request(s)
    count_dict = {}
    with get_redis_connection().map() as redis:
        for user_id in users_dict:
            feed = LoveFeed(user_id, redis=redis)
            count = feed.count()
            count_dict[user_id] = count

    for user_id, count in count_dict.items():
        profile = users_dict[user_id].get_profile()
        redis_count = int(count_dict[user_id])
        db_max = redis_count + 10
        db_count = profile._following_loves().count()
        print profile, db_count, long(redis_count)

    return render_to_response(template, context)
Beispiel #5
0
def index(request, template='feedly/index.html'):
    context = RequestContext(request)
    #HACK for django <1.3 beta compatibility
    if 'STATIC_URL' not in context and 'MEDIA_URL' in context:
        context['STATIC_URL'] = context['MEDIA_URL']
    sample_size = int(request.GET.get('sample_size', 1000))
    context['sample_size'] = sample_size
    lucky_users = random.sample(xrange(10**6), sample_size) + [13]
    users_dict = User.objects.get_cached_users(lucky_users)
    buckets = [
        0, 24, 1 * 24, 3 * 24, 10 * 24, 30 * 24, 50 * 24, 100 * 24, 150 * 24,
        1000 * 24
    ]
    bucket_dict = dict([(b, 0) for b in buckets])
    count_dict = {}

    #retrieve all the counts in one pipelined request(s)
    with get_redis_connection().map() as redis:
        for user_id in users_dict:
            feed = LoveFeed(user_id, redis=redis)
            count = feed.count()
            count_dict[user_id] = count

    #divide into buckets using bisect left
    for user_id, count in count_dict.items():
        bucket_index = bisect.bisect_left(buckets, count)
        bucket = buckets[bucket_index]
        bucket_dict[bucket] += 1
    bucket_stats = bucket_dict.items()
    bucket_stats.sort(key=lambda x: x[0])
    context['bucket_stats'] = bucket_stats

    return render_to_response(template, context)
Beispiel #6
0
    def test_simple_remove_love(self):
        from entity.models import Love
        target_loves = Love.objects.all()[:10]
        feed = LoveFeed(13)
        feed.delete()
        # slow implementation
        activities = []
        for love in target_loves:
            # remove the items by key (id)
            activity = Activity(love.user,
                                LoveVerb,
                                love,
                                love.user,
                                time=love.created_at,
                                extra_context=dict(hello='world'))
            activities.append(activity)
            feed.remove(activity)

        feed.add_many(activities)
        for activity in activities:
            assert feed.contains(activity)
        feed.remove_many(activities)
        assert feed.count() == 0

        feed_loves = feed[:20]
Beispiel #7
0
 def test_small_feed_instance(self):
     loves = Love.objects.all()[:5]
     feed = LoveFeed(13, max_length=2)
     for love in loves:
         activity = Activity(love.user,
                             LoveVerb,
                             love,
                             love.user,
                             time=love.created_at,
                             extra_context=dict(hello='world'))
         feed.add(activity)
     self.assertEqual(feed.count(), feed.max_length)
Beispiel #8
0
    def test_follow(self):
        follow = Follow.objects.filter(user=self.bogus_user)[:1][0]
        # reset the feed
        feed = LoveFeed(follow.user_id)
        feed.delete()
        # do a follow
        feedly = LoveFeedly()
        feed = feedly.follow(follow)
        # see if we got the new loves
        target_loves = follow.target.get_profile().loves()[:10]
        for love in target_loves:
            activity = feedly.create_love_activity(love)
            assert feed.contains(activity)

        # check if we correctly broadcasted
        feedly.unfollow(follow)
        feed_count = feed.count()
        feed_results = feed[:20]
        self.assertEqual(feed_results, [])
Beispiel #9
0
    def test_follow(self):
        follow = Follow.objects.filter(user=self.bogus_user)[:1][0]
        # reset the feed
        feed = LoveFeed(follow.user_id)
        feed.delete()
        # do a follow
        feedly = LoveFeedly()
        feed = feedly.follow(follow)
        # see if we got the new loves
        target_loves = follow.target.get_profile().loves()[:10]
        for love in target_loves:
            activity = feedly.create_love_activity(love)
            assert feed.contains(activity)

        # check if we correctly broadcasted
        feedly.unfollow(follow)
        feed_count = feed.count()
        feed_results = feed[:20]
        self.assertEqual(feed_results, [])
Beispiel #10
0
    def test_simple_remove_love(self):
        from entity.models import Love
        target_loves = Love.objects.all()[:10]
        feed = LoveFeed(13)
        feed.delete()
        # slow implementation
        activities = []
        for love in target_loves:
            # remove the items by key (id)
            activity = Activity(love.user, LoveVerb, love, love.user, time=love.created_at, extra_context=dict(hello='world'))
            activities.append(activity)
            feed.remove(activity)

        feed.add_many(activities)
        for activity in activities:
            assert feed.contains(activity)
        feed.remove_many(activities)
        assert feed.count() == 0

        feed_loves = feed[:20]
Beispiel #11
0
 def test_count(self):
     loves = Love.objects.all()[:10]
     feed = LoveFeed(13)
     feed.finish()
     count_lazy = feed.count()
     count = int(count_lazy)
Beispiel #12
0
 def test_count(self):
     loves = Love.objects.all()[:10]
     feed = LoveFeed(13)
     feed.finish()
     count_lazy = feed.count()
     count = int(count_lazy)