Merge branch 'master' into social

* master:
  Better logging for socket.io. Giving standard users the pulsating real-time spinner.
  Only checking raw parsed hub address 1 in 10 times.

Conflicts:
	templates/reader/feeds.xhtml
This commit is contained in:
Samuel Clay 2012-04-03 22:02:18 -07:00
commit fd0d6f8491
4 changed files with 20 additions and 18 deletions

View file

@ -1,12 +1,13 @@
# Adapted from djpubsubhubbub. See License: http://git.participatoryculture.org/djpubsubhubbub/tree/LICENSE
import feedparser
import random
from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404
from apps.push.models import PushSubscription
from apps.push.signals import verified, updated
from apps.push.signals import verified
def push_callback(request, push_id):
if request.method == 'GET':
@ -34,9 +35,9 @@ def push_callback(request, push_id):
subscription = get_object_or_404(PushSubscription, pk=push_id)
# XXX TODO: Optimize this by removing feedparser. It just needs to find out
# the hub_url or topic has changed. ElementTree could do it.
parsed = feedparser.parse(request.raw_post_data)
subscription.check_urls_against_pushed_data(parsed)
updated.send(sender=subscription, update=parsed)
if random.random() < 0.1:
parsed = feedparser.parse(request.raw_post_data)
subscription.check_urls_against_pushed_data(parsed)
# Don't give fat ping, just fetch.
# subscription.feed.queue_pushed_feed_xml(request.raw_post_data)

View file

@ -6,21 +6,20 @@ REDIS_SERVER = if process.env.NODE_ENV == 'dev' then 'localhost' else 'db01'
client = redis.createClient 6379, REDIS_SERVER
io.sockets.on 'connection', (socket) ->
console.log " ---> New connection brings total to" +
" #{io.sockets.clients().length} consumers."
socket.on 'subscribe:feeds', (feeds, username) ->
socket.on 'subscribe:feeds', (@feeds, @username) ->
console.log " ---> [#{@username}] Subscribing to #{feeds.length} feeds " +
" (#{io.sockets.clients().length} users on)"
socket.subscribe?.end()
socket.subscribe = redis.createClient 6379, REDIS_SERVER
console.log " ---> [#{username}] Subscribing to #{feeds.length} feeds"
socket.subscribe.subscribe feeds
socket.subscribe.subscribe @feeds
socket.subscribe.on 'message', (channel, message) ->
console.log " ---> [#{username}] Update on #{channel}: #{message}"
console.log " ---> [#{@username}] Update on #{channel}: #{message}"
socket.emit 'feed:update', channel
socket.on 'disconnect', () ->
socket.subscribe?.end()
console.log " ---> [] Disconnect, there are now" +
" #{io.sockets.clients().length-1} consumers."
console.log " ---> [#{@username}] Disconnect, there are now" +
" #{io.sockets.clients().length-1} users."

View file

@ -12,22 +12,23 @@
client = redis.createClient(6379, REDIS_SERVER);
io.sockets.on('connection', function(socket) {
console.log(" ---> New connection brings total to" + (" " + (io.sockets.clients().length) + " consumers."));
socket.on('subscribe:feeds', function(feeds, username) {
var _ref;
this.feeds = feeds;
this.username = username;
console.log((" ---> [" + this.username + "] Subscribing to " + feeds.length + " feeds ") + (" (" + (io.sockets.clients().length) + " users on)"));
if ((_ref = socket.subscribe) != null) _ref.end();
socket.subscribe = redis.createClient(6379, REDIS_SERVER);
console.log(" ---> [" + username + "] Subscribing to " + feeds.length + " feeds");
socket.subscribe.subscribe(feeds);
socket.subscribe.subscribe(this.feeds);
return socket.subscribe.on('message', function(channel, message) {
console.log(" ---> [" + username + "] Update on " + channel + ": " + message);
console.log(" ---> [" + this.username + "] Update on " + channel + ": " + message);
return socket.emit('feed:update', channel);
});
});
return socket.on('disconnect', function() {
var _ref;
if ((_ref = socket.subscribe) != null) _ref.end();
return console.log(" ---> [] Disconnect, there are now" + (" " + (io.sockets.clients().length - 1) + " consumers."));
return console.log((" ---> [" + this.username + "] Disconnect, there are now") + (" " + (io.sockets.clients().length - 1) + " users."));
});
});

View file

@ -288,6 +288,7 @@
<span class="NB-module-content-subtitle">
<span class="NB-module-account-feedcount">{{ active_count }}</span> of 64 sites
</span>
<div class="NB-module-content-account-realtime" title=""></div>
Free Standard Account
{% endif %}
</h3>