From 92b615b5030cb03be079b810923c6ac38a3a1bc9 Mon Sep 17 00:00:00 2001 From: Jeff Atwood Date: Sun, 19 Oct 2014 23:14:50 -0700 Subject: [PATCH] reorganize site settings a bit --- app/assets/javascripts/discourse/models/post_stream.js | 4 ++-- app/controllers/topics_controller.rb | 2 +- config/locales/server.en.yml | 2 +- config/site_settings.yml | 8 ++++---- lib/topic_view.rb | 2 +- spec/components/topic_view_spec.rb | 10 +++++----- spec/controllers/topics_controller_spec.rb | 6 +++--- test/javascripts/helpers/site-settings.js | 2 +- test/javascripts/models/post-stream-test.js.es6 | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/discourse/models/post_stream.js b/app/assets/javascripts/discourse/models/post_stream.js index 864c50174..ee69626a1 100644 --- a/app/assets/javascripts/discourse/models/post_stream.js +++ b/app/assets/javascripts/discourse/models/post_stream.js @@ -149,7 +149,7 @@ Discourse.PostStream = Em.Object.extend({ var firstIndex = this.indexOf(firstPost); if (firstIndex === -1) { return []; } - var startIndex = firstIndex - Discourse.SiteSettings.posts_per_page; + var startIndex = firstIndex - Discourse.SiteSettings.posts_chunksize; if (startIndex < 0) { startIndex = 0; } return stream.slice(startIndex, firstIndex); @@ -173,7 +173,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_per_page+1); + return stream.slice(lastIndex+1, lastIndex+Discourse.SiteSettings.posts_chunksize+1); }.property('lastLoadedPost', 'stream.@each'), diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 1d65832bc..1069af4de 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -58,7 +58,7 @@ class TopicsController < ApplicationController end page = params[:page].to_i - if (page < 0) || ((page - 1) * SiteSetting.posts_per_page > @topic_view.topic.highest_post_number) + if (page < 0) || ((page - 1) * SiteSetting.posts_chunksize > @topic_view.topic.highest_post_number) raise Discourse::NotFound end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 318a985b7..39b696a5b 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -733,7 +733,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" - posts_per_page: "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" site_contact_username: "All automated private messages will be from this user; if left blank the default System account will be used." send_welcome_message: "Send all new users a welcome private message with a quick start guide." suppress_reply_directly_below: "Don't show the expandable reply count on a post when there is only a single reply directly below this post." diff --git a/config/site_settings.yml b/config/site_settings.yml index 5583b5307..6e736b48b 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -158,10 +158,6 @@ basic: show_subcategory_list: default: false client: true - posts_per_page: - client: true - default: 20 - min: 1 enable_badges: client: true default: true @@ -632,6 +628,10 @@ developer: verbose_localization: default: false client: true + posts_chunksize: + client: true + default: 20 + min: 1 embedding: embeddable_host: '' diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 44e480e7f..d2620cfcb 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -21,7 +21,7 @@ class TopicView @page = @page.to_i @page = 1 if @page.zero? - @limit ||= SiteSetting.posts_per_page + @limit ||= SiteSetting.posts_chunksize setup_filtered_posts diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index 019f77485..b25263bd9 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -118,7 +118,7 @@ describe TopicView do end it "generates a canonical correctly for paged results" do - SiteSetting.stubs(:posts_per_page).returns(5) + SiteSetting.stubs(:posts_chunksize).returns(5) TopicView.new(1234, user, post_number: 50).canonical_path.should eql("/1234?page=10") end end @@ -136,7 +136,7 @@ describe TopicView do TopicView.any_instance.expects(:find_topic).with(1234).returns(topic) TopicView.any_instance.stubs(:filter_posts) TopicView.any_instance.stubs(:last_post).returns(p2) - SiteSetting.stubs(:posts_per_page).returns(2) + SiteSetting.stubs(:posts_chunksize).returns(2) end it "should return the next page" do @@ -245,7 +245,7 @@ describe TopicView do let!(:p3) { Fabricate(:post, topic: topic, user: first_poster)} before do - SiteSetting.posts_per_page = 3 + SiteSetting.posts_chunksize = 3 # Update them to the sort order we're checking for [p1, p2, p3, p4, p5, p6, p7].each_with_index do |p, idx| @@ -289,7 +289,7 @@ describe TopicView do describe '#filter_posts_paged' do - before { SiteSetting.stubs(:posts_per_page).returns(2) } + before { SiteSetting.stubs(:posts_chunksize).returns(2) } it 'returns correct posts for all pages' do topic_view.filter_posts_paged(1).should == [p1, p2] @@ -362,7 +362,7 @@ describe TopicView do end context "when 'posts per page' exceeds the number of posts" do - before { SiteSetting.stubs(:posts_per_page).returns(100) } + before { SiteSetting.stubs(:posts_chunksize).returns(100) } it 'returns all the posts' do near_view = topic_view_near(p5) diff --git a/spec/controllers/topics_controller_spec.rb b/spec/controllers/topics_controller_spec.rb index a3a025e72..3a59449ad 100644 --- a/spec/controllers/topics_controller_spec.rb +++ b/spec/controllers/topics_controller_spec.rb @@ -656,19 +656,19 @@ describe TopicsController do context 'filters' do it 'grabs first page when no filter is provided' do - SiteSetting.stubs(:posts_per_page).returns(20) + SiteSetting.stubs(:posts_chunksize).returns(20) TopicView.any_instance.expects(:filter_posts_in_range).with(0, 19) xhr :get, :show, topic_id: topic.id, slug: topic.slug end it 'grabs first page when first page is provided' do - SiteSetting.stubs(:posts_per_page).returns(20) + SiteSetting.stubs(:posts_chunksize).returns(20) TopicView.any_instance.expects(:filter_posts_in_range).with(0, 19) xhr :get, :show, topic_id: topic.id, slug: topic.slug, page: 1 end it 'grabs correct range when a page number is provided' do - SiteSetting.stubs(:posts_per_page).returns(20) + SiteSetting.stubs(:posts_chunksize).returns(20) TopicView.any_instance.expects(:filter_posts_in_range).with(20, 39) xhr :get, :show, topic_id: topic.id, slug: topic.slug, page: 2 end diff --git a/test/javascripts/helpers/site-settings.js b/test/javascripts/helpers/site-settings.js index e1a4f1783..5985a9461 100644 --- a/test/javascripts/helpers/site-settings.js +++ b/test/javascripts/helpers/site-settings.js @@ -1,3 +1,3 @@ /*jshint maxlen:10000000 */ -Discourse.SiteSettingsOriginal = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","mobile_logo_url":"","favicon_url":"//meta.discourse.org/uploads/default/2499/79d53726406d87af.ico","allow_user_locale":false,"suggested_topics":7,"track_external_right_clicks":false,"ga_universal_tracking_code":"","ga_universal_domain_name":"auto","ga_tracking_code":"UA-33736483-2","ga_domain_name":"","top_menu":"latest|new|unread|starred|categories|top","post_menu":"like|share|flag|edit|bookmark|delete|admin|reply","post_menu_hidden_items":"edit|delete|admin","share_links":"twitter|facebook|google+|email","category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","enable_mobile_theme":true,"relative_date_duration":14,"category_featured_topics":4,"fixed_category_positions":false,"show_subcategory_list":false,"posts_per_page":20,"enable_badges":true,"invite_only":false,"login_required":false,"must_approve_users":false,"enable_local_logins":true,"allow_new_registrations":true,"enable_google_logins":true,"enable_google_oauth2_logins":false,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_github_logins":true,"enable_sso":false,"min_username_length":3,"max_username_length":20,"min_password_length":8,"enable_names":true,"invites_shown":30,"delete_user_max_post_age":60,"delete_all_posts_max":15,"min_post_length":20,"min_private_message_post_length":10,"max_post_length":32000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_title_similar_length":10,"min_body_similar_length":15,"edit_history_visible_to_public":true,"delete_removed_posts_after":24,"traditional_markdown_linebreaks":false,"suppress_reply_directly_below":true,"suppress_reply_directly_above":true,"newuser_max_images":0,"newuser_max_attachments":0,"display_name_on_posts":true,"short_progress_text_threshold":10000,"default_code_lang":"lang-auto","autohighlight_all_code":false,"email_in":false,"max_image_size_kb":3072,"max_attachment_size_kb":1024,"authorized_extensions":".jpg|.jpeg|.png|.gif|.svg|.txt|.ico|.yml","max_image_width":690,"max_image_height":500,"allow_profile_backgrounds":true,"allow_uploaded_avatars":true,"allow_animated_avatars":false,"tl1_requires_read_posts":30,"enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"flush_timings_secs":5,"tos_url":"","privacy_policy_url":"","tos_accept_required":false,"faq_url":"","allow_restore":false,"maximum_backups":7,"version_checks":true,"suppress_uncategorized_badge":true,"min_search_term_length":3,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"global_notice":"","show_create_topics_notice":true,"available_locales":"cs|da|de|en|es|fr|he|id|it|ja|ko|nb_NO|nl|pl_PL|pt|pt_BR|ru|sv|uk|zh_CN|zh_TW"}; +Discourse.SiteSettingsOriginal = {"title":"Discourse Meta","logo_url":"/assets/logo.png","logo_small_url":"/assets/logo-single.png","mobile_logo_url":"","favicon_url":"//meta.discourse.org/uploads/default/2499/79d53726406d87af.ico","allow_user_locale":false,"suggested_topics":7,"track_external_right_clicks":false,"ga_universal_tracking_code":"","ga_universal_domain_name":"auto","ga_tracking_code":"UA-33736483-2","ga_domain_name":"","top_menu":"latest|new|unread|starred|categories|top","post_menu":"like|share|flag|edit|bookmark|delete|admin|reply","post_menu_hidden_items":"edit|delete|admin","share_links":"twitter|facebook|google+|email","category_colors":"BF1E2E|F1592A|F7941D|9EB83B|3AB54A|12A89D|25AAE2|0E76BD|652D90|92278F|ED207B|8C6238|231F20|808281|B3B5B4|283890","enable_mobile_theme":true,"relative_date_duration":14,"category_featured_topics":4,"fixed_category_positions":false,"show_subcategory_list":false,"posts_chunksize":20,"enable_badges":true,"invite_only":false,"login_required":false,"must_approve_users":false,"enable_local_logins":true,"allow_new_registrations":true,"enable_google_logins":true,"enable_google_oauth2_logins":false,"enable_yahoo_logins":true,"enable_twitter_logins":true,"enable_facebook_logins":true,"enable_github_logins":true,"enable_sso":false,"min_username_length":3,"max_username_length":20,"min_password_length":8,"enable_names":true,"invites_shown":30,"delete_user_max_post_age":60,"delete_all_posts_max":15,"min_post_length":20,"min_private_message_post_length":10,"max_post_length":32000,"min_topic_title_length":15,"max_topic_title_length":255,"min_private_message_title_length":2,"allow_uncategorized_topics":true,"min_title_similar_length":10,"min_body_similar_length":15,"edit_history_visible_to_public":true,"delete_removed_posts_after":24,"traditional_markdown_linebreaks":false,"suppress_reply_directly_below":true,"suppress_reply_directly_above":true,"newuser_max_images":0,"newuser_max_attachments":0,"display_name_on_posts":true,"short_progress_text_threshold":10000,"default_code_lang":"lang-auto","autohighlight_all_code":false,"email_in":false,"max_image_size_kb":3072,"max_attachment_size_kb":1024,"authorized_extensions":".jpg|.jpeg|.png|.gif|.svg|.txt|.ico|.yml","max_image_width":690,"max_image_height":500,"allow_profile_backgrounds":true,"allow_uploaded_avatars":true,"allow_animated_avatars":false,"tl1_requires_read_posts":30,"enable_long_polling":true,"polling_interval":3000,"anon_polling_interval":30000,"flush_timings_secs":5,"tos_url":"","privacy_policy_url":"","tos_accept_required":false,"faq_url":"","allow_restore":false,"maximum_backups":7,"version_checks":true,"suppress_uncategorized_badge":true,"min_search_term_length":3,"topic_views_heat_low":1000,"topic_views_heat_medium":2000,"topic_views_heat_high":5000,"global_notice":"","show_create_topics_notice":true,"available_locales":"cs|da|de|en|es|fr|he|id|it|ja|ko|nb_NO|nl|pl_PL|pt|pt_BR|ru|sv|uk|zh_CN|zh_TW"}; Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal); diff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6 index 3e65a9484..dcb06d130 100644 --- a/test/javascripts/models/post-stream-test.js.es6 +++ b/test/javascripts/models/post-stream-test.js.es6 @@ -182,7 +182,7 @@ test("loading", function() { }); test("nextWindow", function() { - Discourse.SiteSettings.posts_per_page = 5; + Discourse.SiteSettings.posts_chunksize = 5; var postStream = buildStream(1234, [1,2,3,5,8,9,10,11,13,14,15,16]); blank(postStream.get('nextWindow'), 'With no posts loaded, the window is blank'); @@ -199,7 +199,7 @@ test("nextWindow", function() { }); test("previousWindow", function() { - Discourse.SiteSettings.posts_per_page = 5; + Discourse.SiteSettings.posts_chunksize = 5; var postStream = buildStream(1234, [1,2,3,5,8,9,10,11,13,14,15,16]); blank(postStream.get('previousWindow'), 'With no posts loaded, the window is blank');