Skip to content

Commit 52b5fc3

Browse files
committed
Do not check if a page is saved if a user has no session header
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?
1 parent e691f0c commit 52b5fc3

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

app/controllers/content_items_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ def save_this_page_enabled?
225225
helper_method :logged_in?
226226

227227
def user_has_saved_page?
228+
return false unless @account_session_header
229+
228230
GdsApi.account_api.get_saved_page(
229231
page_path: request.path,
230232
govuk_account_session: @account_session_header,

test/controllers/save_a_page_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ class ContentItemsControllerTest < ActionController::TestCase
1616
end
1717

1818
test "logged out - shows the add_page_button when the feature flag is on" do
19+
stub_feature_flag_on
20+
set_up_and_visit_content_item("detailed_guide", "detailed_guide")
21+
22+
assert has_save_page_button("/guidance/salary-sacrifice-and-the-effects-on-paye")
23+
end
24+
25+
test "invalid session - shows the add_page_button when the feature flag is on" do
1926
stub_feature_flag_on
2027
stub_account_api_unauthorized_get_saved_page(page_path: "/guidance/salary-sacrifice-and-the-effects-on-paye")
2128
set_up_and_visit_content_item("detailed_guide", "detailed_guide")

0 commit comments

Comments
 (0)