diff --git a/app/presenters/filtered_editions_presenter.rb b/app/presenters/filtered_editions_presenter.rb index 55b436d5a..ef8f1244d 100644 --- a/app/presenters/filtered_editions_presenter.rb +++ b/app/presenters/filtered_editions_presenter.rb @@ -59,6 +59,12 @@ def assignees end def editions + @editions ||= query_editions + end + +private + + def query_editions result = editions_by_content_type result = apply_states_filter(result) result = apply_assigned_to_filter(result) @@ -68,8 +74,6 @@ def editions result.order_by(%w[updated_at desc]).page(@page).per(ITEMS_PER_PAGE) end -private - def available_users User.enabled.alphabetized end diff --git a/test/unit/presenters/filtered_editions_presenter_test.rb b/test/unit/presenters/filtered_editions_presenter_test.rb index 9963d022c..f4cfb7eda 100644 --- a/test/unit/presenters/filtered_editions_presenter_test.rb +++ b/test/unit/presenters/filtered_editions_presenter_test.rb @@ -199,6 +199,14 @@ def a_gds_user assert_equal(middle, filtered_editions[1]) assert_equal(oldest, filtered_editions[2]) end + + should "only query the database once, regardless of how many times it is called" do + presenter = FilteredEditionsPresenter.new(a_gds_user) + presenter.expects(:query_editions).once.returns([]) + + presenter.editions + presenter.editions + end end context "#assignees" do