Skip to content

Commit

Permalink
Do not check if a page is saved if a user has no session header
Browse files Browse the repository at this point in the history
I spotted that the account-api was getting a *lot* of saved-page
queries in staging, which I tracked down to this: we're checking if
the page is saved even if the user has no session (which will always
fail).  We can skip the API call in that case.

We had a similar issue once in the Transition Checker, where we were
trying to fetch saved results regardless of whether the user had a
session or not.  Since this has come up twice now we should think
about how this problem can be solved generically.  Maybe we could put
more logic in gds-api-adapters, for example?
  • Loading branch information
barrucadu committed Jul 15, 2021
1 parent e691f0c commit 52b5fc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def save_this_page_enabled?
helper_method :logged_in?

def user_has_saved_page?
return false unless @account_session_header

GdsApi.account_api.get_saved_page(
page_path: request.path,
govuk_account_session: @account_session_header,
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/save_a_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class ContentItemsControllerTest < ActionController::TestCase
end

test "logged out - shows the add_page_button when the feature flag is on" do
stub_feature_flag_on
set_up_and_visit_content_item("detailed_guide", "detailed_guide")

assert has_save_page_button("/guidance/salary-sacrifice-and-the-effects-on-paye")
end

test "invalid session - shows the add_page_button when the feature flag is on" do
stub_feature_flag_on
stub_account_api_unauthorized_get_saved_page(page_path: "/guidance/salary-sacrifice-and-the-effects-on-paye")
set_up_and_visit_content_item("detailed_guide", "detailed_guide")
Expand Down

0 comments on commit 52b5fc3

Please sign in to comment.