diff --git a/lib/pact_broker/matrix/parse_query.rb b/lib/pact_broker/matrix/parse_query.rb index 698fd0f64..ec79e5e04 100644 --- a/lib/pact_broker/matrix/parse_query.rb +++ b/lib/pact_broker/matrix/parse_query.rb @@ -28,6 +28,9 @@ def self.call query if params.key?('groupby') options[:groupby] = params['groupby'] end + if params.key?('limit') + options[:limit] = params['limit'] + end return selectors, options end end diff --git a/lib/pact_broker/matrix/repository.rb b/lib/pact_broker/matrix/repository.rb index 15bb91929..d87faa37c 100644 --- a/lib/pact_broker/matrix/repository.rb +++ b/lib/pact_broker/matrix/repository.rb @@ -70,6 +70,8 @@ def find_all selectors, options query = where_consumer_and_provider_in(selectors, query) end + query = query.limit(options[:limit]) if options[:limit] + query.order(:verification_executed_at, :verification_id).all end diff --git a/lib/pact_broker/ui/controllers/matrix.rb b/lib/pact_broker/ui/controllers/matrix.rb index cb851470d..c50c2fa23 100644 --- a/lib/pact_broker/ui/controllers/matrix.rb +++ b/lib/pact_broker/ui/controllers/matrix.rb @@ -11,7 +11,7 @@ class Matrix < Base get "/provider/:provider_name/consumer/:consumer_name" do selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] } ] - lines = matrix_service.find(selectors) + lines = matrix_service.find(selectors, {latestby: 'cvpv', limit: 500}) lines = lines.collect{|line| PactBroker::UI::ViewDomain::MatrixLine.new(line) }.sort locals = { lines: lines, diff --git a/spec/lib/pact_broker/matrix/repository_spec.rb b/spec/lib/pact_broker/matrix/repository_spec.rb index fadee98d8..faca2e7cd 100644 --- a/spec/lib/pact_broker/matrix/repository_spec.rb +++ b/spec/lib/pact_broker/matrix/repository_spec.rb @@ -42,6 +42,7 @@ def shorten_rows rows end subject { shorten_rows(Repository.new.find(selectors, options)) } + let(:options) { { latestby: latestby } } let(:latestby) { nil } let(:a1_b1_n1) { "A1 B1 n1" } @@ -50,6 +51,15 @@ def shorten_rows rows let(:a1_c1_n1) { "A1 C1 n1" } let(:a2_b__n_) { "A2 B? n?" } + context "when a limit is specified" do + let(:selectors) { build_selectors('A' => nil) } + let(:options) { {limit: 1} } + + it "returns fewer rows than the limit (because some of the logic is done in the code, there may be fewer than the limit - need to fix this)" do + expect(subject.size).to eq 1 + end + end + context "when just the consumer name is specified" do let(:selectors) { build_selectors('A' => nil) }