Skip to content

Commit

Permalink
Adding update_counts to /feeds API endpoint, to force a recalculation…
Browse files Browse the repository at this point in the history
… of feed unread counts (WARNING: slower than calling /feeds then /refresh_feeds).
  • Loading branch information
samuelclay committed Nov 7, 2011
1 parent 7c92c92 commit 936774b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions apps/reader/views.py
Expand Up @@ -159,6 +159,7 @@ def load_feeds(request):
not_yet_fetched = False
include_favicons = request.REQUEST.get('include_favicons', False)
flat = request.REQUEST.get('flat', False)
update_counts = request.REQUEST.get('update_counts', False)

if flat: return load_feeds_flat(request)

Expand All @@ -175,6 +176,8 @@ def load_feeds(request):

for sub in user_subs:
pk = sub.feed.pk
if update_counts:
sub.calculate_feed_scores(silent=True)
feeds[pk] = sub.canonical(include_favicon=include_favicons)
if feeds[pk].get('not_yet_fetched'):
not_yet_fetched = True
Expand Down
4 changes: 2 additions & 2 deletions media/js/newsblur/reader.js
Expand Up @@ -4933,8 +4933,8 @@
this.model.save_exception_retry(feed_id, _.bind(this.force_feed_refresh, this, feed_id, $feed));
},

setup_socket_realtime_unread_counts: function() {
if (!this.socket && NEWSBLUR.Globals.is_premium && NEWSBLUR.Globals.username == 'samuel') {
setup_socket_realtime_unread_counts: function(force) {
if (force && !this.socket) {
this.socket = this.socket || io.connect('http://' + window.location.hostname + ':8888');

// this.socket.refresh_feeds = _.debounce(_.bind(this.force_feeds_refresh, this), 1000*10);
Expand Down
2 changes: 1 addition & 1 deletion settings.py
Expand Up @@ -183,7 +183,7 @@
'js/jquery.fieldselection.js',
'js/jquery.flot.js',
'js/jquery.tipsy.js',
'js/socket.io-client.0.8.7.js',
# 'js/socket.io-client.0.8.7.js',
'js/underscore.js',
'js/underscore.string.js',
'js/newsblur/reader_utils.js',
Expand Down
9 changes: 9 additions & 0 deletions templates/static/api.yml
Expand Up @@ -84,6 +84,15 @@
optional: true
default: "false"
example: "true/false"
- key: update_counts
desc: >
Forces recalculation of unread counts on all feeds. The preferred method is
to call this endpoint without updated counts, then call refresh_feeds to get
updated counts. That way you can quickly show the user's feeds, then update
the counts. Turning this option on will lead to a slower load-time.
optional: true
default: "false"
example: "true/false"

- url: /reader/favicons
method: GET
Expand Down

0 comments on commit 936774b

Please sign in to comment.