4
4
require 'pact_broker/matrix/head_row'
5
5
require 'pact_broker/matrix/aggregated_row'
6
6
require 'pact_broker/repositories/helpers'
7
+ require 'pact_broker/index/page'
7
8
8
9
module PactBroker
9
10
module Index
@@ -20,6 +21,8 @@ class Service
20
21
Sequel . desc ( :consumer_version_order ) ,
21
22
Sequel . asc ( Sequel . function ( :lower , :provider_name ) )
22
23
] . freeze
24
+ DEFAULT_PAGE_SIZE = 30
25
+ DEFAULT_PAGE_NUMBER = 1
23
26
24
27
# This method provides data for both the OSS server side rendered index (with and without tags)
25
28
# and the Pactflow UI. It really needs to be broken into to separate methods, as it's getting too messy
@@ -77,6 +80,7 @@ def self.find_index_items_optimised options = {}
77
80
webhooks = PactBroker ::Webhooks ::Webhook . select ( :consumer_id , :provider_id ) . distinct . all
78
81
79
82
pact_publication_ids = head_pact_publication_ids ( options )
83
+ pagination_record_count = pact_publication_ids . pagination_record_count
80
84
81
85
pact_publications = PactBroker ::Pacts ::PactPublication
82
86
. where ( id : pact_publication_ids )
@@ -89,7 +93,7 @@ def self.find_index_items_optimised options = {}
89
93
. eager ( latest_verification : { provider_version : :tags_with_latest_flag } )
90
94
. eager ( :head_pact_tags )
91
95
92
- pact_publications . all . collect do | pact_publication |
96
+ index_items = pact_publications . all . collect do | pact_publication |
93
97
is_overall_latest_for_integration = latest_pact_publication_ids . include? ( pact_publication . id )
94
98
latest_verification = latest_verification_for_pseudo_branch ( pact_publication , is_overall_latest_for_integration , latest_verifications_for_cv_tags , options [ :tags ] )
95
99
webhook = webhooks . find { |webhook | webhook . is_for? ( pact_publication . integration ) }
@@ -106,6 +110,8 @@ def self.find_index_items_optimised options = {}
106
110
options [ :tags ] && latest_verification ? latest_verification . provider_version . tags_with_latest_flag . select ( &:latest? ) : [ ]
107
111
)
108
112
end . sort
113
+
114
+ Page . new ( index_items , pagination_record_count )
109
115
end
110
116
111
117
# Worst. Code. Ever.
@@ -193,8 +199,7 @@ def self.head_pact_publication_ids(options = {})
193
199
end
194
200
195
201
query . order ( *HEAD_PP_ORDER_COLUMNS )
196
- . limit ( options [ :limit ] || 50 )
197
- . offset ( options [ :offset ] || 0 )
202
+ . paginate ( options [ :page_number ] || DEFAULT_PAGE_NUMBER , options [ :page_size ] || DEFAULT_PAGE_SIZE )
198
203
. select ( :id )
199
204
end
200
205
0 commit comments