From 00e59bdc620bd4a41929fac7a1110860bcb1e411 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 25 Aug 2015 15:40:50 +1000 Subject: [PATCH] FIX: display warning when user is tracking too many topics FEATURE: allow admins to bump up number of tracked topics if needed using max_tracked_new_unread --- .../discourse/controllers/discovery/topics.js.es6 | 4 ++++ .../javascripts/discourse/models/topic-tracking-state.js.es6 | 5 +++++ .../javascripts/discourse/templates/discovery/topics.hbs | 4 ++++ app/models/topic_tracking_state.rb | 2 +- config/locales/client.en.yml | 1 + config/locales/server.en.yml | 1 + config/site_settings.yml | 3 +++ 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 index ac534b96183..772c8e4c5b7 100644 --- a/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 +++ b/app/assets/javascripts/discourse/controllers/discovery/topics.js.es6 @@ -95,6 +95,10 @@ const controllerOpts = { return this.get('model.filter') === 'new' && this.get('model.topics.length') > 0; }.property('model.filter', 'model.topics.length'), + tooManyTracked: function(){ + return Discourse.TopicTrackingState.current().tooManyTracked(); + }.property(), + showDismissAtTop: function() { return (this.isFilterPage(this.get('model.filter'), 'new') || this.isFilterPage(this.get('model.filter'), 'unread')) && diff --git a/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6 b/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6 index 051a7b03287..cf5f8903751 100644 --- a/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6 +++ b/app/assets/javascripts/discourse/models/topic-tracking-state.js.es6 @@ -237,6 +237,10 @@ const TopicTrackingState = Discourse.Model.extend({ .length; }, + tooManyTracked() { + return this.initialStatesLength >= Discourse.SiteSettings.max_tracked_new_unread; + }, + resetNew() { const self = this; Object.keys(this.states).forEach(function (id) { @@ -308,6 +312,7 @@ TopicTrackingState.reopenClass({ instance = Discourse.TopicTrackingState.create({ messageBus, currentUser }); instance.loadStates(data); + instance.initialStatesLength = data && data.length; instance.establishChannels(); return instance; }, diff --git a/app/assets/javascripts/discourse/templates/discovery/topics.hbs b/app/assets/javascripts/discourse/templates/discovery/topics.hbs index f3e452a4ab0..e95136eacab 100644 --- a/app/assets/javascripts/discourse/templates/discovery/topics.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/topics.hbs @@ -1,3 +1,7 @@ +{{#if tooManyTracked}} +
{{i18n 'topics.too_many_tracked'}}
+{{/if}} + {{#if redirectedReason}}
{{redirectedReason}}
{{/if}} diff --git a/app/models/topic_tracking_state.rb b/app/models/topic_tracking_state.rb index 12370fa234b..b6fae15187a 100644 --- a/app/models/topic_tracking_state.rb +++ b/app/models/topic_tracking_state.rb @@ -166,7 +166,7 @@ SQL sql << " AND topics.id = :topic_id" end - sql << " ORDER BY topics.bumped_at DESC ) SELECT * FROM x LIMIT 500" + sql << " ORDER BY topics.bumped_at DESC ) SELECT * FROM x LIMIT #{SiteSetting.max_tracked_new_unread.to_i}" SqlBuilder.new(sql) .map_exec(TopicTrackingState, user_id: user_id, topic_id: topic_id) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 472d780b431..86c437496b5 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -936,6 +936,7 @@ en: current_user: 'go to your user page' topics: + too_many_tracked: "Warning: you have too many tracked new and unread topics, clear some using \"Dismiss New\" or \"Dismiss Posts\"" bulk: reset_read: "Reset Read" delete: "Delete Topics" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 57f4a7ef4f3..8ea0218b32b 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -946,6 +946,7 @@ en: active_user_rate_limit_secs: "How frequently we update the 'last_seen_at' field, in seconds" verbose_localization: "Show extended localization tips in the UI" + max_tracked_new_unread: "Cap the total of new + unread topics per user, this protects database and client from very large payloads for some users tracking thousands of topics" previous_visit_timeout_hours: "How long a visit lasts before we consider it the 'previous' visit, in hours" rate_limit_create_topic: "After creating a topic, users must wait (n) seconds before creating another topic." diff --git a/config/site_settings.yml b/config/site_settings.yml index 7720cf89030..d9c16cb10aa 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -748,6 +748,9 @@ developer: migrate_to_new_scheme: hidden: true default: false + max_tracked_new_unread: + default: 1000 + client: true embedding: feed_polling_enabled: