From bf6e9ce6b49f5e33bfe53f560f28fac15c9ea307 Mon Sep 17 00:00:00 2001 From: Evan Farrar Date: Tue, 14 Feb 2023 19:44:42 +0000 Subject: [PATCH] Exclude app usage events table from using window function Co-authored-by: Evan Farrar Co-authored-by: Seth Boyles --- app/models/runtime/app_usage_event.rb | 5 +++++ .../paging/sequel_paginator_spec.rb | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/app/models/runtime/app_usage_event.rb b/app/models/runtime/app_usage_event.rb index b1cb8a18161..b0200910578 100644 --- a/app/models/runtime/app_usage_event.rb +++ b/app/models/runtime/app_usage_event.rb @@ -9,5 +9,10 @@ class AppUsageEvent < Sequel::Model :buildpack_guid, :buildpack_name, :package_state, :previous_package_state, :parent_app_guid, :parent_app_name, :process_type, :task_name, :task_guid + AppUsageEvent.dataset_module do + def supports_window_functions? + false + end + end end end diff --git a/spec/unit/lib/cloud_controller/paging/sequel_paginator_spec.rb b/spec/unit/lib/cloud_controller/paging/sequel_paginator_spec.rb index ad2c3721fc9..e87aa891a79 100644 --- a/spec/unit/lib/cloud_controller/paging/sequel_paginator_spec.rb +++ b/spec/unit/lib/cloud_controller/paging/sequel_paginator_spec.rb @@ -148,6 +148,26 @@ module VCAP::CloudController end end + context 'AppUsageEvents table' do + before do + AppUsageEvent.make(guid: '1', created_at: '2022-12-20T10:47:01Z') + AppUsageEvent.make(guid: '2', created_at: '2022-12-20T10:47:02Z') + AppUsageEvent.make(guid: '3', created_at: '2022-12-20T10:47:03Z') + AppUsageEvent.make(guid: '4', created_at: '2022-12-20T10:47:04Z') + end + + it 'does not use window function' do + options = { page: page, per_page: per_page } + pagination_options = PaginationOptions.new(options) + + paginated_result = nil + expect { + paginated_result = paginator.get_page(AppUsageEvent.dataset, pagination_options) + }.to have_queried_db_times(/over/i, 0) + expect(paginated_result.total).to be > 1 + end + end + it 'returns correct total results for distinct result' do options = { page: page, per_page: per_page, order_by: :key_name } pagination_options = PaginationOptions.new(options)