Cleaning up unfetched feeds and finishing rewrite of refreshing feeds.

This commit is contained in:
Samuel Clay 2012-05-22 17:39:21 -07:00
parent f969fbf45b
commit fc817e7048
9 changed files with 147 additions and 139 deletions

View file

@ -168,7 +168,8 @@ class UserSubscription(models.Model):
'id': feed_id,
}
if not sub.feed.fetched_once or check_fetch_status:
feeds[feed_id]['not_yet_fetched'] = not sub.feed.fetched_once
feeds[feed_id]['fetched_once'] = sub.feed.fetched_once
feeds[feed_id]['not_yet_fetched'] = not sub.feed.fetched_once # Legacy. Dammit.
if sub.feed.favicon_fetching:
feeds[feed_id]['favicon_fetching'] = True
if sub.feed.has_feed_exception or sub.feed.has_page_exception:

View file

@ -169,7 +169,6 @@ def autologin(request, username, secret):
def load_feeds(request):
user = get_user(request)
feeds = {}
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)
@ -197,8 +196,6 @@ def load_feeds(request):
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
if not sub.feed.active and not sub.feed.has_feed_exception and not sub.feed.has_page_exception:
sub.feed.count_subscribers()
sub.feed.schedule_feed_fetch_immediately()
@ -206,11 +203,6 @@ def load_feeds(request):
sub.feed.count_subscribers()
sub.feed.schedule_feed_fetch_immediately()
if not_yet_fetched:
for f in feeds:
if 'not_yet_fetched' not in feeds[f]:
feeds[f]['not_yet_fetched'] = False
starred_count = MStarredStory.objects(user_id=user.pk).count()
social_params = {

View file

@ -102,6 +102,8 @@ class Feed(models.Model):
'updated_seconds_ago': seconds_timesince(self.last_update),
'subs': self.num_subscribers,
'is_push': self.is_push,
'fetched_once': self.fetched_once,
'not_yet_fetched': not self.fetched_once, # Legacy. Doh.
'favicon_color': self.favicon_color,
'favicon_fade': self.favicon_fade(),
'favicon_border': self.favicon_border(),
@ -116,8 +118,6 @@ class Feed(models.Model):
feed['favicon'] = feed_icon.data
except MFeedIcon.DoesNotExist:
pass
if not self.fetched_once:
feed['not_yet_fetched'] = True
if self.has_page_exception or self.has_feed_exception:
feed['has_exception'] = True
feed['exception_type'] = 'feed' if self.has_feed_exception else 'page'

View file

@ -98,7 +98,7 @@
if (feed.has_exception && feed.exception_type == 'feed') {
exception_class += ' NB-feed-exception';
}
if (feed.not_yet_fetched && !feed.has_exception) {
if (!feed.fetched_once && !feed.has_exception) {
exception_class += ' NB-feed-unfetched';
}

View file

@ -544,14 +544,13 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
},
post_refresh_feeds: function(data, callback) {
var updated_feeds = [];
if (!data.feeds) return;
_.each(data.feeds, _.bind(function(feed, feed_id) {
var existing_feed = this.feeds.get(feed_id);
if (!existing_feed) return;
var feed_id = feed.id || feed_id;
if (feed.id && feed_id != feed.id) {
NEWSBLUR.log(['Dupe feed being refreshed', feed_id, feed.id, this.feeds.get(f), feed]);
this.feeds.get(feed.id).set(feed);
@ -560,34 +559,25 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
(existing_feed.get('has_exception') && !feed['has_exception'])) {
existing_feed.set('has_exception', !!feed['has_exception']);
}
existing_feed.set(feed, {silent: true});
if (feed['favicon'] && existing_feed.get('favicon') != feed['favicon']) {
existing_feed.set('favicon', feed['favicon']);
existing_feed.set('favicon_color', feed['favicon_color']);
existing_feed.set('favicon_fetching', false);
}
if (existing_feed.hasChanged() && !_.contains(updated_feeds, feed.id)) {
NEWSBLUR.log(['Different', existing_feed.changedAttributes(), existing_feed.previousAttributes()]);
updated_feeds.push(feed_id);
existing_feed.set({
'favicon': feed['favicon'],
'favicon_color': feed['favicon_color'],
'favicon_fetching': false
});
}
existing_feed.set(feed);
}, this));
_.each(data.social_feeds, _.bind(function(feed) {
var social_feed = this.social_feeds.get(feed.id);
if (!social_feed) return;
for (var k in feed) {
if (social_feed.get(k) != feed[k]) {
social_feed.set(k, feed[k]);
}
}
if (social_feed.hasChanged() && !_.contains(updated_feeds, feed.id)) {
updated_feeds.push(feed.id);
}
social_feed.set(feed);
}, this));
callback(updated_feeds);
callback && callback();
},
refresh_feed: function(feed_id, callback) {
@ -617,7 +607,7 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
count_unfetched_feeds: function() {
var counts = this.feeds.reduce(function(counts, feed) {
if (feed.get('active')) {
if (!feed.get('not_yet_fetched') || feed.get('has_exception')) {
if (feed.get('fetched_once') || feed.get('has_exception')) {
counts['fetched_feeds'] += 1;
} else {
counts['unfetched_feeds'] += 1;

View file

@ -1,7 +1,20 @@
NEWSBLUR.Models.Feed = Backbone.Model.extend({
initialize: function() {
_.bindAll(this, 'on_change');
this.bind('change', this.on_change);
},
on_change: function() {
NEWSBLUR.log(['Feed Change', this.changedAttributes(), this.previousAttributes()]);
},
is_social: function() {
return false;
},
is_feed: function() {
return true;
}
});

View file

@ -8,6 +8,10 @@ NEWSBLUR.Models.SocialSubscription = Backbone.Model.extend({
is_social: function() {
return true;
},
is_feed: function() {
return false;
}
});

View file

@ -502,10 +502,6 @@
},
find_feed_in_feed_list: function(feed_id) {
if (_.contains(this.cache.$feed_in_feed_list, feed_id)) {
return this.cache.$feed_in_feed_list[feed_id];
}
var $feed_list = this.$s.$feed_list.parent();
var $feeds = $([]);
if (feed_id) {
@ -918,6 +914,7 @@
var scroll = $feed.position().top;
var container = $feed_lists.scrollTop();
var height = $feed_lists.outerHeight();
console.log(["scroll to feed", $feed[0], scroll, container, height, container_offset]);
$feed_lists.scrollTop(scroll+container-height/5);
}
},
@ -5870,10 +5867,14 @@
force_instafetch_stories: function(feed_id) {
var self = this;
feed_id = feed_id || this.active_feed;
var $feed = this.find_feed_in_feed_list(feed_id);
$feed.addClass('NB-feed-unfetched').removeClass('NB-feed-exception');
var feed = this.model.get_feed(feed_id);
feed.set({
fetched_once: false,
has_exception: false
});
this.model.save_exception_retry(feed_id, _.bind(this.force_feed_refresh, this, feed_id), this.show_stories_error);
this.model.save_exception_retry(feed_id, _.bind(this.force_feed_refresh, this, feed_id),
this.show_stories_error);
},
setup_socket_realtime_unread_counts: function(force) {
@ -5936,7 +5937,7 @@
setup_feed_refresh: function(new_feeds) {
var self = this;
var refresh_interval = this.constants.FEED_REFRESH_INTERVAL;
var feed_count = _.size(this.model.feeds);
var feed_count = this.model.feeds.size();
if (!NEWSBLUR.Globals.is_premium) {
refresh_interval *= 2;
@ -5981,14 +5982,12 @@
var $feed = this.find_feed_in_feed_list(feed_id);
new_feed_id = new_feed_id || feed_id;
this.force_feeds_refresh(function(feeds) {
var $new_feed = $(self.make_feed_title_template(feeds[new_feed_id], 'feed'));
if ($feed.hasClass('NB-toplevel')) $new_feed.addClass('NB-toplevel');
$feed.replaceWith($new_feed);
this.force_feeds_refresh(function() {
// Open the feed back up if it is being refreshed and is still open.
self.cache.$feed_in_feed_list[feed_id] = null;
self.cache.$feed_in_feed_list[new_feed_id] = null;
if (self.active_feed == feed_id || self.active_feed == new_feed_id) {
self.open_feed(new_feed_id, {force: true, $feed_link: $new_feed});
self.open_feed(new_feed_id, {force: true});
}
}, true, new_feed_id, this.show_stories_error);
},
@ -6014,25 +6013,23 @@
delete this.cache.refresh_callback;
}
for (var f in updated_feeds) {
var feed_id = updated_feeds[f];
var feed = this.model.get_feed(feed_id);
if (!feed) continue;
if (_.string.include(feed_id, 'social:')) {
this.replace_social_feed_in_feedlist(feed_id);
} else {
this.replace_feed_in_feedlist(feed_id, {
replace_active_feed: replace_active_feed,
single_feed_id: single_feed_id
});
}
}
// _.each(updated_feeds, _.bind(function(feed_id) {
// var feed = this.model.get_feed(feed_id);
// if (!feed) return;
// // if (_.string.include(feed_id, 'social:')) {
// // this.replace_social_feed_in_feedlist(feed_id);
// // } else {
// // this.replace_feed_in_feedlist(feed_id, {
// // replace_active_feed: replace_active_feed,
// // single_feed_id: single_feed_id
// // });
// // }
// }, this));
this.flags['refresh_inline_feed_delay'] = false;
this.flags['pause_feed_refreshing'] = false;
this.check_feed_fetch_progress();
this.count_collapsed_unread_stories();
this.flags['pause_feed_refreshing'] = false;
},
replace_feed_in_feedlist: function(feed_id, options) {
@ -6047,45 +6044,45 @@
// this.model.refresh_feed(feed_id, $.rescope(this.post_refresh_active_feed, this));
// Set the unread counts to what the client thinks they are, so when
// the counts can be updated, they will force a refresh of the feed.
this.model.feeds[feed_id].ps = parseInt($('.unread_count_positive', $feed_on_page).text(), 10);
this.model.feeds[feed_id].nt = parseInt($('.unread_count_neutral', $feed_on_page).text(), 10);
this.model.feeds[feed_id].ng = parseInt($('.unread_count_negative', $feed_on_page).text(), 10);
// this.model.feeds[feed_id].ps = parseInt($('.unread_count_positive', $feed_on_page).text(), 10);
// this.model.feeds[feed_id].nt = parseInt($('.unread_count_neutral', $feed_on_page).text(), 10);
// this.model.feeds[feed_id].ng = parseInt($('.unread_count_negative', $feed_on_page).text(), 10);
} else {
if ($feed_on_page.hasClass('NB-toplevel')) $feed.addClass('NB-toplevel');
$feed_on_page.replaceWith($feed);
this.cache.$feed_in_feed_list[feed_id] = null;
this.mark_feed_as_selected(this.active_feed);
if (!options.single_feed_id) this.recalculate_story_scores(feed_id);
// if ($feed_on_page.hasClass('NB-toplevel')) $feed.addClass('NB-toplevel');
// $feed_on_page.replaceWith($feed);
// this.cache.$feed_in_feed_list[feed_id] = null;
// this.mark_feed_as_selected(this.active_feed);
// if (!options.single_feed_id) this.recalculate_story_scores(feed_id);
this.show_feed_hidden_story_title_indicator();
this.make_content_pane_feed_counter();
// this.make_content_pane_feed_counter();
}
} else {
if (!this.flags['has_unfetched_feeds']) {
NEWSBLUR.log(['UPDATING', feed.get('feed_title'), $feed, $feed_on_page]);
}
if ($feed_on_page.hasClass('NB-toplevel')) $feed.addClass('NB-toplevel');
$feed_on_page.replaceWith($feed);
this.cache.$feed_in_feed_list[feed_id] = null;
(function($feed) {
$feed.css({'backgroundColor': '#D7DDE6'});
$feed.animate({
'backgroundColor': '#F0F076'
}, {
'duration': 800,
'queue': false,
'complete': function() {
$feed.animate({'backgroundColor': '#D7DDE6'}, {
'duration': 1000,
'queue': false,
'complete': function() {
if ($feed_on_page.hasClass('NB-selected')) {
$feed.addClass('NB-selected');
}
}
});
}
});
})($feed);
// if ($feed_on_page.hasClass('NB-toplevel')) $feed.addClass('NB-toplevel');
// $feed_on_page.replaceWith($feed);
// this.cache.$feed_in_feed_list[feed_id] = null;
// (function($feed) {
// $feed.css({'backgroundColor': '#D7DDE6'});
// $feed.animate({
// 'backgroundColor': '#F0F076'
// }, {
// 'duration': 800,
// 'queue': false,
// 'complete': function() {
// $feed.animate({'backgroundColor': '#D7DDE6'}, {
// 'duration': 1000,
// 'queue': false,
// 'complete': function() {
// if ($feed_on_page.hasClass('NB-selected')) {
// $feed.addClass('NB-selected');
// }
// }
// });
// }
// });
// })($feed);
}
},
@ -6094,43 +6091,43 @@
var $feed = $(this.make_feed_title_template(feed, 'feed', 0));
var $feed_on_page = this.find_feed_in_feed_list(feed_id);
if (feed_id == this.active_feed && !this.flags.refresh_inline_feed_delay) {
NEWSBLUR.log(['UPDATING INLINE (social)', feed.get('feed_title')]);
// Set the unread counts to what the client thinks they are, so when
// the counts can be updated, they will force a refresh of the feed.
var social_feed = this.model.social_feeds.get(feed_id);
social_feed.set('ps', parseInt($('.unread_count_positive', $feed_on_page).text(), 10));
social_feed.set('nt', parseInt($('.unread_count_neutral', $feed_on_page).text(), 10));
social_feed.set('ng', parseInt($('.unread_count_negative', $feed_on_page).text(), 10));
// NEWSBLUR.log(['UPDATING INLINE (social)', feed.get('feed_title')]);
// // Set the unread counts to what the client thinks they are, so when
// // the counts can be updated, they will force a refresh of the feed.
// var social_feed = this.model.social_feeds.get(feed_id);
// social_feed.set('ps', parseInt($('.unread_count_positive', $feed_on_page).text(), 10));
// social_feed.set('nt', parseInt($('.unread_count_neutral', $feed_on_page).text(), 10));
// social_feed.set('ng', parseInt($('.unread_count_negative', $feed_on_page).text(), 10));
} else {
if (!this.flags['has_unfetched_feeds']) {
NEWSBLUR.log(['UPDATING (social)', feed.get('feed_title')]);
}
// if (!this.flags['has_unfetched_feeds']) {
// NEWSBLUR.log(['UPDATING (social)', feed.get('feed_title')]);
// }
// If the social feed has no shared stories but is updating, it's because it now does.
// But it's only provided in real-time. This is a fallback for polling refreshes.
if (!feed.shared_stories_count) this.model.social_feeds.get(feed_id).set('shared_stories_count', 1);
if ($feed_on_page.hasClass('NB-toplevel')) $feed.addClass('NB-toplevel');
$feed_on_page.replaceWith($feed);
this.cache.$feed_in_feed_list[feed_id] = null;
(function($feed) {
$feed.css({'backgroundColor': '#C6D3E6'});
$feed.animate({
'backgroundColor': '#F0F076'
}, {
'duration': 800,
'queue': false,
'complete': function() {
$feed.animate({'backgroundColor': '#C6D3E6'}, {
'duration': 1000,
'queue': false,
'complete': function() {
if ($feed_on_page.hasClass('NB-selected')) {
$feed.addClass('NB-selected');
}
}
});
}
});
})($feed);
// if ($feed_on_page.hasClass('NB-toplevel')) $feed.addClass('NB-toplevel');
// $feed_on_page.replaceWith($feed);
// this.cache.$feed_in_feed_list[feed_id] = null;
// (function($feed) {
// $feed.css({'backgroundColor': '#C6D3E6'});
// $feed.animate({
// 'backgroundColor': '#F0F076'
// }, {
// 'duration': 800,
// 'queue': false,
// 'complete': function() {
// $feed.animate({'backgroundColor': '#C6D3E6'}, {
// 'duration': 1000,
// 'queue': false,
// 'complete': function() {
// if ($feed_on_page.hasClass('NB-selected')) {
// $feed.addClass('NB-selected');
// }
// }
// });
// }
// });
// })($feed);
}
},

View file

@ -29,15 +29,19 @@ NEWSBLUR.Views.Feed = Backbone.View.extend({
},
changed: function(model, options) {
var counts_changed = options.changes && _.any(_.keys(options.changes), function(key) {
return _.contains(['ps', 'nt', 'ng'], key);
});
var only_counts_changed = options.changes && !_.any(_.keys(options.changes), function(key) {
return !_.contains(['ps', 'nt', 'ng'], key);
});
if (only_counts_changed && !options.instant) {
this.flash_changes();
if (only_counts_changed) {
this.add_extra_classes();
} else if (!only_counts_changed) {
if (!options.instant) this.flash_changes();
} else {
this.render();
if (!options.instant && counts_changed) this.flash_changes();
}
},
@ -93,6 +97,7 @@ NEWSBLUR.Views.Feed = Backbone.View.extend({
extra_classes: function() {
var feed = this.model;
var extra_classes = '';
if (feed.get('ps')) {
extra_classes += ' unread_positive';
}
@ -102,17 +107,23 @@ NEWSBLUR.Views.Feed = Backbone.View.extend({
if (feed.get('ng')) {
extra_classes += ' unread_negative';
}
if (feed.get('has_exception') && feed.get('exception_type') == 'feed') {
extra_classes += ' NB-feed-exception';
if (feed.is_feed()) {
if (feed.get('has_exception') && feed.get('exception_type') == 'feed') {
extra_classes += ' NB-feed-exception';
}
if (!feed.get('fetched_once') && !feed.get('has_exception')) {
extra_classes += ' NB-feed-unfetched';
}
if (!feed.get('active') && !feed.get('subscription_user_id')) {
extra_classes += ' NB-feed-inactive';
}
}
if (feed.get('not_yet_fetched') && !feed.get('has_exception')) {
extra_classes += ' NB-feed-unfetched';
}
if (!feed.get('active') && !feed.get('subscription_user_id')) {
extra_classes += ' NB-feed-inactive';
}
if (feed.get('subscription_user_id') && !feed.get('shared_stories_count')) {
extra_classes += ' NB-feed-inactive';
if (feed.is_social()) {
if (feed.get('subscription_user_id') && !feed.get('shared_stories_count')) {
extra_classes += ' NB-feed-inactive';
}
}
return extra_classes;
},