Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place /stats routes behind login check, for performance reasons #9536

Merged
merged 5 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class StatsController < ApplicationController
before_action :require_user, only: %i(index range notes wikis users questions comments tags)

def subscriptions
@tags = Rails.cache.fetch("stats-subscriptions-query", expires_in: 24.hours) do
TagSelection
Expand Down
7 changes: 7 additions & 0 deletions test/functional/stats_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ def setup
@start = 1.month.ago
@end = Date.today
@stats = [:notes, :comments, :users, :wikis, :questions, :answers, :tags, :node_tags]
activate_authlogic
end

test 'should assign correct value to graph_notes on GET stats' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
Node.delete_all
Node.create!(type: 'note', title:'blah', uid: 1, status: 1)
get :index, params: { start: @start.to_s, end: @end.to_s }
assert_kind_of Hash, Node.contribution_graph_making('note', @start.to_time, @end.to_time)
end

test 'should assign correct value to graph_wikis on GET stats' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
Node.delete_all
Node.create(type: 'note', title: 'blah', uid: 1, status: 1)
Node.create(type: 'page', title: 'blahblah', uid: 1, status: 1)
Expand All @@ -24,6 +27,7 @@ def setup
end

test 'should assign correct value to graph_comments on GET stats' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
Comment.delete_all
Comment.create!(comment: 'blah', timestamp: Time.now - 1)
get :index, params: { start: @start.to_s, end: @end.to_s }
Expand All @@ -32,6 +36,7 @@ def setup
end

test 'should load stats range query' do
UserSession.create(users(:bob)) # we now require login for this page for load reasons
get :index
assert_response :success
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should this be a 302 redirect???

assert_not_nil assigns(:notes)
Expand All @@ -48,6 +53,7 @@ def setup
end

def csv_stats_download
UserSession.create(users(:bob)) # we now require login for this page for load reasons
@stats.each do |action|
test "should download #{action} as csv" do
get action, params: { format: 'csv' }
Expand All @@ -59,6 +65,7 @@ def csv_stats_download
end

def json_stats_downloads
UserSession.create(users(:bob)) # we now require login for this page for load reasons
@stats.each do |action|
test "should download #{action} as json" do
get action, params: { format: 'json' }
Expand Down
10 changes: 10 additions & 0 deletions test/integration/I18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,16 @@ class I18nTest < ActionDispatch::IntegrationTest
available_testing_locales.each do |lang|
get '/change_locale/' + lang.to_s
follow_redirect!

post '/user_sessions',
params: {
user_session: {
username: users(:jeff).username,
password: 'secretive'
}
}
follow_redirect!

start_time = 1.month.ago
end_time = Date.today
@graph_notes = Node.contribution_graph_making('note', start_time.to_time, end_time.to_time)
Expand Down
5 changes: 0 additions & 5 deletions test/integration/public_pages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ def setup
assert_redirected_to '/search?q=foo'
end

test 'browse /stats' do
get '/stats'
assert_response :success
end

test 'browse redirected node' do
get nodes(:redirect).path
assert_response :redirect
Expand Down