Skip to content

Commit 989e6e3

Browse files
committed
feat(matrix): refresh head matrix asynchronously to speed up pact publishing and tagging
1 parent ecfca29 commit 989e6e3

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require 'sucker_punch'
2+
require 'pact_broker/matrix/head_row'
3+
4+
module PactBroker
5+
module Matrix
6+
class RefreshHeadMatrixJob
7+
8+
include SuckerPunch::Job
9+
include PactBroker::Logging
10+
11+
def perform params
12+
PactBroker::Matrix::HeadRow.refresh(params[:params])
13+
end
14+
end
15+
end
16+
end

lib/pact_broker/matrix/repository.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
require 'pact_broker/matrix/row'
33
require 'pact_broker/matrix/latest_row'
44
require 'pact_broker/matrix/head_row'
5+
require 'pact_broker/matrix/refresh_head_matrix_job'
56
require 'pact_broker/error'
67

8+
79
module PactBroker
810
module Matrix
911

@@ -23,7 +25,7 @@ class Repository
2325

2426
def refresh params
2527
PactBroker::Matrix::Row.refresh(params)
26-
PactBroker::Matrix::HeadRow.refresh(params)
28+
RefreshHeadMatrixJob.perform_in(1, params: params)
2729
end
2830

2931
# Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number
@@ -128,11 +130,13 @@ def look_up_versions_for_latest_and_tag(selectors, options)
128130
end
129131
end.collect do | selector |
130132
if selector[:pacticipant_name]
131-
selector[:pacticipant_id] = PactBroker::Domain::Pacticipant.find(name: selector[:pacticipant_name]).id
133+
pacticipant = PactBroker::Domain::Pacticipant.find(name: selector[:pacticipant_name])
134+
selector[:pacticipant_id] = pacticipant ? pacticipant.id : nil
132135
end
133136

134137
if selector[:pacticipant_name] && selector[:pacticipant_version_number]
135-
selector[:pacticipant_version_id] = version_repository.find_by_pacticipant_name_and_number(selector[:pacticipant_name], selector[:pacticipant_version_number]).id
138+
version = version_repository.find_by_pacticipant_name_and_number(selector[:pacticipant_name], selector[:pacticipant_version_number])
139+
selector[:pacticipant_version_id] = version ? version.id : nil
136140
end
137141

138142
if selector[:pacticipant_version_number].nil?

lib/pact_broker/matrix/row.rb

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'pact_broker/repositories/helpers'
22
require 'pact_broker/webhooks/latest_triggered_webhook'
33
require 'pact_broker/tags/tag_with_latest_flag'
4+
require 'pact_broker/logging'
45

56
module PactBroker
67
module Matrix
@@ -16,8 +17,11 @@ class Row < Sequel::Model(:materialized_matrix)
1617

1718
dataset_module do
1819
include PactBroker::Repositories::Helpers
20+
include PactBroker::Logging
1921

2022
def refresh params
23+
logger.debug("Refreshing #{model.table_name} for #{params}")
24+
2125
source_view_name = model.table_name.to_s.gsub('materialized_', '').to_sym
2226
if params[:consumer_name] || params[:provider_name]
2327
criteria = {}

0 commit comments

Comments
 (0)