Throttling dashboard story retrieval.

This commit is contained in:
Samuel Clay 2021-05-12 18:36:25 -04:00
parent 2f602a8d85
commit 3afd50a061
2 changed files with 23 additions and 9 deletions

View file

@ -17,6 +17,7 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
this.starred_feeds = new NEWSBLUR.Collections.StarredFeeds();
this.searches_feeds = new NEWSBLUR.Collections.SearchesFeeds();
this.queued_read_stories = {};
this.queued_realtime_stories = {};
this.classifiers = {};
this.friends = {};
this.profile = {};
@ -819,19 +820,32 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
add_dashboard_story: function(story_hash, dashboard_stories) {
var self = this;
var pre_callback = function(data) {
dashboard_stories.add(data.stories, {silent: true});
dashboard_stories.limit_visible_on_dashboard(NEWSBLUR.Globals.is_premium ? 5 : 3);
dashboard_stories.trigger('reset', {added: 1});
};
this.make_request('/reader/river_stories', {
h: story_hash,
dashboard: true
}, pre_callback, null, {
'ajax_group': 'dashboard',
'request_type': 'GET'
});
if (!('hashes' in this.queued_realtime_stories)) { this.queued_realtime_stories['hashes'] = []; }
this.queued_realtime_stories['hashes'].push(story_hash);
// NEWSBLUR.log(['Marking real-time load', this.queued_realtime_stories['hashes'], story_hash]);
this.throttled_add_dashboard_story = this.throttled_add_dashboard_story || _.throttle(_.bind(function () {
this.make_request('/reader/river_stories', {
h: this.queued_realtime_stories['hashes'],
dashboard: true
}, pre_callback, null, {
'ajax_group': 'dashboard',
'request_type': 'GET',
'ajax_group': 'queue_clear',
'beforeSend': function () {
// NEWSBLUR.log(['Clearing realtime stories', self.queued_realtime_stories['hashes']])
self.queued_realtime_stories = {};
}
});
}, this), 1000);
this.throttled_add_dashboard_story();
},
fetch_river_blurblogs_stories: function(feed_id, page, options, callback, error_callback, first_load) {

View file

@ -417,9 +417,9 @@ NEWSBLUR.Views.DashboardRiver = Backbone.View.extend({
return;
}
_.delay(_.bind(function() {
// _.delay(_.bind(function() {
NEWSBLUR.assets.add_dashboard_story(story_hash, this.options.dashboard_stories);
}, this), Math.random() * delay);
// }, this), Math.random() * delay);
},