mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Load fewer posts when the android platform is detected
This commit is contained in:
@@ -1,11 +1,3 @@
|
||||
/**
|
||||
Our data model for interacting with site settings.
|
||||
|
||||
@class SiteSetting
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.SiteSetting = Discourse.Model.extend({
|
||||
|
||||
validationMessage: null,
|
||||
|
||||
@@ -1,59 +1,17 @@
|
||||
/**
|
||||
We use this class to keep on top of streaming and filtering posts within a topic.
|
||||
|
||||
@class PostStream
|
||||
@extends Ember.Object
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.PostStream = Em.Object.extend({
|
||||
|
||||
/**
|
||||
Are we currently loading posts in any way?
|
||||
|
||||
@property loading
|
||||
**/
|
||||
loading: Em.computed.or('loadingAbove', 'loadingBelow', 'loadingFilter', 'stagingPost'),
|
||||
|
||||
notLoading: Em.computed.not('loading'),
|
||||
|
||||
filteredPostsCount: Em.computed.alias("stream.length"),
|
||||
|
||||
/**
|
||||
Have we loaded any posts?
|
||||
|
||||
@property hasPosts
|
||||
**/
|
||||
hasPosts: function(){
|
||||
hasPosts: function() {
|
||||
return this.get('posts.length') > 0;
|
||||
}.property("posts.@each"),
|
||||
|
||||
/**
|
||||
Do we have a stream list of post ids?
|
||||
|
||||
@property hasStream
|
||||
**/
|
||||
hasStream: Em.computed.gt('filteredPostsCount', 0),
|
||||
|
||||
/**
|
||||
Can we append more posts to our current stream?
|
||||
|
||||
@property canAppendMore
|
||||
**/
|
||||
canAppendMore: Em.computed.and('notLoading', 'hasPosts', 'lastPostNotLoaded'),
|
||||
|
||||
/**
|
||||
Can we prepend more posts to our current stream?
|
||||
|
||||
@property canPrependMore
|
||||
**/
|
||||
canPrependMore: Em.computed.and('notLoading', 'hasPosts', 'firstPostNotLoaded'),
|
||||
|
||||
/**
|
||||
Have we loaded the first post in the stream?
|
||||
|
||||
@property firstPostPresent
|
||||
**/
|
||||
firstPostPresent: function() {
|
||||
if (!this.get('hasLoadedData')) { return false; }
|
||||
return !!this.get('posts').findProperty('id', this.get('firstPostId'));
|
||||
@@ -61,47 +19,22 @@ Discourse.PostStream = Em.Object.extend({
|
||||
|
||||
firstPostNotLoaded: Em.computed.not('firstPostPresent'),
|
||||
|
||||
/**
|
||||
The first post that we have loaded. Useful for checking to see if we should scroll upwards
|
||||
|
||||
@property firstLoadedPost
|
||||
**/
|
||||
firstLoadedPost: function() {
|
||||
return _.first(this.get('posts'));
|
||||
}.property('posts.@each'),
|
||||
|
||||
/**
|
||||
The last post we have loaded. Useful for checking to see if we should load more
|
||||
|
||||
@property lastLoadedPost
|
||||
**/
|
||||
lastLoadedPost: function() {
|
||||
return _.last(this.get('posts'));
|
||||
}.property('posts.@each'),
|
||||
|
||||
/**
|
||||
Returns the id of the first post in the set
|
||||
|
||||
@property firstPostId
|
||||
**/
|
||||
firstPostId: function() {
|
||||
return this.get('stream')[0];
|
||||
}.property('stream.@each'),
|
||||
|
||||
/**
|
||||
Returns the id of the last post in the set
|
||||
|
||||
@property lastPostId
|
||||
**/
|
||||
lastPostId: function() {
|
||||
return _.last(this.get('stream'));
|
||||
}.property('stream.@each'),
|
||||
|
||||
/**
|
||||
Have we loaded the last post in the stream?
|
||||
|
||||
@property loadedAllPosts
|
||||
**/
|
||||
loadedAllPosts: function() {
|
||||
if (!this.get('hasLoadedData')) { return false; }
|
||||
return !!this.get('posts').findProperty('id', this.get('lastPostId'));
|
||||
@@ -149,7 +82,7 @@ Discourse.PostStream = Em.Object.extend({
|
||||
var firstIndex = this.indexOf(firstPost);
|
||||
if (firstIndex === -1) { return []; }
|
||||
|
||||
var startIndex = firstIndex - Discourse.SiteSettings.posts_chunksize;
|
||||
var startIndex = firstIndex - this.get('topic.chunk_size');
|
||||
if (startIndex < 0) { startIndex = 0; }
|
||||
return stream.slice(startIndex, firstIndex);
|
||||
|
||||
@@ -173,7 +106,7 @@ Discourse.PostStream = Em.Object.extend({
|
||||
if ((lastIndex + 1) >= this.get('highest_post_number')) { return []; }
|
||||
|
||||
// find our window of posts
|
||||
return stream.slice(lastIndex+1, lastIndex+Discourse.SiteSettings.posts_chunksize+1);
|
||||
return stream.slice(lastIndex+1, lastIndex + this.get('topic.chunk_size') + 1);
|
||||
}.property('lastLoadedPost', 'stream.@each'),
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
/**
|
||||
A data model representing the site (instance of Discourse)
|
||||
|
||||
@class Site
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.Site = Discourse.Model.extend({
|
||||
|
||||
isReadOnly: Em.computed.alias('is_readonly'),
|
||||
|
||||
@@ -47,6 +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[:username_filters] = username_filters.split(',') if username_filters.is_a?(String)
|
||||
|
||||
begin
|
||||
@@ -58,7 +59,7 @@ class TopicsController < ApplicationController
|
||||
end
|
||||
|
||||
page = params[:page].to_i
|
||||
if (page < 0) || ((page - 1) * SiteSetting.posts_chunksize > @topic_view.topic.highest_post_number)
|
||||
if (page < 0) || ((page - 1) * @topic_view.chunk_size > @topic_view.topic.highest_post_number)
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
||||
|
||||
@@ -42,8 +42,8 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
:has_deleted,
|
||||
:actions_summary,
|
||||
:expandable_first_post,
|
||||
:is_warning
|
||||
|
||||
:is_warning,
|
||||
:chunk_size
|
||||
|
||||
# Define a delegator for each attribute of the topic we want
|
||||
attributes(*topic_attributes)
|
||||
@@ -113,6 +113,9 @@ class TopicViewSerializer < ApplicationSerializer
|
||||
result
|
||||
end
|
||||
|
||||
def chunk_size
|
||||
object.chunk_size
|
||||
end
|
||||
|
||||
def is_warning
|
||||
object.topic.private_message? && object.topic.subtype == TopicSubtype.moderator_warning
|
||||
|
||||
Reference in New Issue
Block a user