mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FEATURE: Load fewer topics in the topic list on slow platforms (Android)
This commit is contained in:
parent
a014507da4
commit
b1bc4741b1
9 changed files with 29 additions and 11 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue