mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -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) {
|
from: function(result, filter, params) {
|
||||||
var topicList = Discourse.TopicList.create({
|
var topicList = Discourse.TopicList.create({
|
||||||
inserted: Em.A(),
|
inserted: [],
|
||||||
filter: filter,
|
filter: filter,
|
||||||
params: params || {},
|
params: params || {},
|
||||||
topics: Discourse.TopicList.topicsFrom(result),
|
topics: Discourse.TopicList.topicsFrom(result),
|
||||||
|
@ -181,7 +181,8 @@ Discourse.TopicList.reopenClass({
|
||||||
draft_sequence: result.topic_list.draft_sequence,
|
draft_sequence: result.topic_list.draft_sequence,
|
||||||
draft: result.topic_list.draft,
|
draft: result.topic_list.draft,
|
||||||
for_period: result.topic_list.for_period,
|
for_period: result.topic_list.for_period,
|
||||||
loaded: true
|
loaded: true,
|
||||||
|
per_page: result.topic_list.per_page
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.topic_list.filtered_category) {
|
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
|
// Try to use the cached version if it exists and is greater than the topics per page
|
||||||
if (cachedList && (cachedList.get('filter') === filter) &&
|
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)) {
|
_.isEqual(cachedList.get('listParams'), filterParams)) {
|
||||||
cachedList.set('loaded', true);
|
cachedList.set('loaded', true);
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ class ApplicationController < ActionController::Base
|
||||||
@use_crawler_layout ||= (has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent))
|
@use_crawler_layout ||= (has_escaped_fragment? || CrawlerDetection.crawler?(request.user_agent))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def slow_platform?
|
||||||
|
request.user_agent =~ /Android/
|
||||||
|
end
|
||||||
|
|
||||||
def set_layout
|
def set_layout
|
||||||
use_crawler_layout? ? 'crawler' : 'application'
|
use_crawler_layout? ? 'crawler' : 'application'
|
||||||
end
|
end
|
||||||
|
|
|
@ -264,6 +264,7 @@ class ListController < ApplicationController
|
||||||
search: params[:search]
|
search: params[:search]
|
||||||
}
|
}
|
||||||
options[:no_subcategories] = true if params[:no_subcategories] == 'true'
|
options[:no_subcategories] = true if params[:no_subcategories] == 'true'
|
||||||
|
options[:slow_platform] = true if slow_platform?
|
||||||
|
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TopicsController < ApplicationController
|
||||||
opts = params.slice(:username_filters, :filter, :page, :post_number, :show_deleted)
|
opts = params.slice(:username_filters, :filter, :page, :post_number, :show_deleted)
|
||||||
username_filters = opts[:username_filters]
|
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)
|
opts[:username_filters] = username_filters.split(',') if username_filters.is_a?(String)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -9,7 +9,8 @@ class TopicList
|
||||||
:draft_key,
|
:draft_key,
|
||||||
:draft_sequence,
|
:draft_sequence,
|
||||||
:filter,
|
:filter,
|
||||||
:for_period
|
:for_period,
|
||||||
|
:per_page
|
||||||
|
|
||||||
def initialize(filter, current_user, topics, opts=nil)
|
def initialize(filter, current_user, topics, opts=nil)
|
||||||
@filter = filter
|
@filter = filter
|
||||||
|
|
|
@ -5,7 +5,8 @@ class TopicListSerializer < ApplicationSerializer
|
||||||
:draft,
|
:draft,
|
||||||
:draft_key,
|
:draft_key,
|
||||||
:draft_sequence,
|
:draft_sequence,
|
||||||
:for_period
|
:for_period,
|
||||||
|
:per_page
|
||||||
|
|
||||||
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
|
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ class TopicListSerializer < ApplicationSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_more_topics_url?
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -738,6 +738,7 @@ en:
|
||||||
share_links: "Determine which items appear on the share dialog, and in what order."
|
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"
|
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"
|
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_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)"
|
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."
|
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:
|
topics_per_page:
|
||||||
default: 30
|
default: 30
|
||||||
min: 1
|
min: 1
|
||||||
client: true
|
slow_topics_per_page:
|
||||||
|
default: 15
|
||||||
|
min: 1
|
||||||
show_subcategory_list:
|
show_subcategory_list:
|
||||||
default: false
|
default: false
|
||||||
client: true
|
client: true
|
||||||
|
|
|
@ -25,6 +25,7 @@ class TopicQuery
|
||||||
status
|
status
|
||||||
state
|
state
|
||||||
search
|
search
|
||||||
|
slow_platform
|
||||||
).map(&:to_sym)
|
).map(&:to_sym)
|
||||||
|
|
||||||
# Maps `order` to a columns in `topics`
|
# Maps `order` to a columns in `topics`
|
||||||
|
@ -155,15 +156,21 @@ class TopicQuery
|
||||||
|
|
||||||
protected
|
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)
|
def create_list(filter, options={}, topics = nil)
|
||||||
topics ||= default_results(options)
|
topics ||= default_results(options)
|
||||||
topics = yield(topics) if block_given?
|
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
|
end
|
||||||
|
|
||||||
def private_messages_for(user)
|
def private_messages_for(user)
|
||||||
options = @options
|
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
|
# Start with a list of all topics
|
||||||
result = Topic.includes(:allowed_users)
|
result = Topic.includes(:allowed_users)
|
||||||
|
@ -230,7 +237,7 @@ class TopicQuery
|
||||||
# Create results based on a bunch of default options
|
# Create results based on a bunch of default options
|
||||||
def default_results(options={})
|
def default_results(options={})
|
||||||
options.reverse_merge!(@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
|
# Start with a list of all topics
|
||||||
result = Topic.unscoped
|
result = Topic.unscoped
|
||||||
|
|
Loading…
Reference in a new issue