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 4 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
6 changes: 6 additions & 0 deletions test/functional/stats_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ def setup
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 +26,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 +35,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 +52,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 +64,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
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