diff --git a/app/assets/javascripts/discourse/models/topic_list.js b/app/assets/javascripts/discourse/models/topic_list.js index d3758dca3..4d70739bd 100644 --- a/app/assets/javascripts/discourse/models/topic_list.js +++ b/app/assets/javascripts/discourse/models/topic_list.js @@ -171,7 +171,7 @@ Discourse.TopicList.reopenClass({ from: function(result, filter, params) { var topicList = Discourse.TopicList.create({ - inserted: Em.A(), + inserted: [], filter: filter, params: params || {}, topics: Discourse.TopicList.topicsFrom(result), @@ -181,7 +181,8 @@ Discourse.TopicList.reopenClass({ draft_sequence: result.topic_list.draft_sequence, draft: result.topic_list.draft, for_period: result.topic_list.for_period, - loaded: true + loaded: true, + per_page: result.topic_list.per_page }); if (result.topic_list.filtered_category) { @@ -212,7 +213,7 @@ Discourse.TopicList.reopenClass({ // Try to use the cached version if it exists and is greater than the topics per page if (cachedList && (cachedList.get('filter') === filter) && - (cachedList.get('topics.length') || 0) > Discourse.SiteSettings.topics_per_page && + (cachedList.get('topics.length') || 0) > cachedList.get('per_page') && _.isEqual(cachedList.get('listParams'), filterParams)) { cachedList.set('loaded', true); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 342943447..eb911760e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -51,6 +51,10 @@ class ApplicationController < ActionController::Base @use_crawler_layout ||= (has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent)) end + def slow_platform? + request.user_agent =~ /Android/ + end + def set_layout use_crawler_layout? ? 'crawler' : 'application' end diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 717bd0a8a..4b715511f 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -264,6 +264,7 @@ class ListController < ApplicationController search: params[:search] } options[:no_subcategories] = true if params[:no_subcategories] == 'true' + options[:slow_platform] = true if slow_platform? options end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 55038625d..63b45f734 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -47,7 +47,7 @@ class TopicsController < ApplicationController opts = params.slice(:username_filters, :filter, :page, :post_number, :show_deleted) username_filters = opts[:username_filters] - opts[:slow_platform] = true if request.user_agent =~ /Android/ + opts[:slow_platform] = true if slow_platform? opts[:username_filters] = username_filters.split(',') if username_filters.is_a?(String) begin diff --git a/app/models/topic_list.rb b/app/models/topic_list.rb index 0d9980d2d..20d438fc4 100644 --- a/app/models/topic_list.rb +++ b/app/models/topic_list.rb @@ -9,7 +9,8 @@ class TopicList :draft_key, :draft_sequence, :filter, - :for_period + :for_period, + :per_page def initialize(filter, current_user, topics, opts=nil) @filter = filter diff --git a/app/serializers/topic_list_serializer.rb b/app/serializers/topic_list_serializer.rb index f459261ae..619388814 100644 --- a/app/serializers/topic_list_serializer.rb +++ b/app/serializers/topic_list_serializer.rb @@ -5,7 +5,8 @@ class TopicListSerializer < ApplicationSerializer :draft, :draft_key, :draft_sequence, - :for_period + :for_period, + :per_page has_many :topics, serializer: TopicListItemSerializer, embed: :objects @@ -18,7 +19,7 @@ class TopicListSerializer < ApplicationSerializer end def include_more_topics_url? - object.more_topics_url.present? && (object.topics.size == SiteSetting.topics_per_page) + object.more_topics_url.present? && (object.topics.size == object.per_page) end end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 64c6e6ab4..feb40ec93 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -738,6 +738,7 @@ en: share_links: "Determine which items appear on the share dialog, and in what order." track_external_right_clicks: "Track external links that are right clicked (eg: open in new tab) disabled by default because it rewrites URLs" topics_per_page: "How many topics are loaded by default on the topic list, and when scrolling down to load more topics" + slow_topics_per_page: "The amount of topics per page on slow devices such as Android" posts_chunksize: "How many posts are loaded by default on a topic, and when scrolling down to load more posts" posts_slow_chunksize: "Like `posts_chunksize` but for slow platforms (such as Android)" site_contact_username: "All automated private messages will be from this user; if left blank the default System account will be used." diff --git a/config/site_settings.yml b/config/site_settings.yml index 90b031808..0aa779a9e 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -154,7 +154,9 @@ basic: topics_per_page: default: 30 min: 1 - client: true + slow_topics_per_page: + default: 15 + min: 1 show_subcategory_list: default: false client: true diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 159c1e838..f56d08a4f 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -25,6 +25,7 @@ class TopicQuery status state search + slow_platform ).map(&:to_sym) # Maps `order` to a columns in `topics` @@ -155,15 +156,21 @@ class TopicQuery protected + def per_page_setting + @options[:slow_platform] ? SiteSetting.slow_topics_per_page : SiteSetting.topics_per_page + end + def create_list(filter, options={}, topics = nil) topics ||= default_results(options) topics = yield(topics) if block_given? - TopicList.new(filter, @user, topics, options.merge(@options)) + list = TopicList.new(filter, @user, topics, options.merge(@options)) + list.per_page = per_page_setting + list end def private_messages_for(user) options = @options - options.reverse_merge!(per_page: SiteSetting.topics_per_page) + options.reverse_merge!(per_page: per_page_setting) # Start with a list of all topics result = Topic.includes(:allowed_users) @@ -230,7 +237,7 @@ class TopicQuery # Create results based on a bunch of default options def default_results(options={}) options.reverse_merge!(@options) - options.reverse_merge!(per_page: SiteSetting.topics_per_page) + options.reverse_merge!(per_page: per_page_setting) # Start with a list of all topics result = Topic.unscoped