Skip to content

Commit 1459b46

Browse files
committed
feat(matrix): handle overwritten revisions in database rather than code
1 parent f38eeae commit 1459b46

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

lib/pact_broker/matrix/repository.rb

+7-15
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,20 @@ def apply_latestby options, selectors, lines
116116

117117
# The group with the nil provider_version_numbers will be the results of the left outer join
118118
# that don't have verifications, so we need to include them all.
119-
remove_overwritten_revisions(lines).group_by{|line| group_by_columns.collect{|key| line.send(key) }}
119+
lines.group_by{|line| group_by_columns.collect{|key| line.send(key) }}
120120
.values
121121
.collect{ | lines | lines.first.provider_version_number.nil? ? lines : lines.first }
122122
.flatten
123123
end
124124

125-
# It would be nicer to do this in the SQL, but it requires time that I don't have at the moment
126-
def remove_overwritten_revisions lines
127-
latest_revisions_keys = {}
128-
latest_revisions = []
129-
lines.each do | line |
130-
key = "#{line.consumer_name}-#{line.provider_name}-#{line.consumer_version_number}"
131-
if !latest_revisions_keys.key?(key) || latest_revisions_keys[key] == line.pact_revision_number
132-
latest_revisions << line
133-
latest_revisions_keys[key] ||= line.pact_revision_number
134-
end
125+
def query_matrix selectors, options
126+
query = Row
127+
if options[:latestby]
128+
query = query.where(pact_publication_id: Row.db[:latest_pact_publication_ids_for_consumer_versions].select(:pact_publication_id))
135129
end
136-
latest_revisions
137-
end
138130

139-
def query_matrix selectors, options
140-
query = Row.select_all.matching_selectors(selectors)
131+
query = query.select_all.matching_selectors(selectors)
132+
141133
query = query.limit(options[:limit]) if options[:limit]
142134
query
143135
.order_by_names_ascending_most_recent_first

0 commit comments

Comments
 (0)