4
4
5
5
module PactBroker
6
6
module Matrix
7
- class Row < Sequel ::Model ( :matrix )
7
+ class Row < Sequel ::Model ( :materialized_matrix )
8
8
9
9
associate ( :one_to_many , :latest_triggered_webhooks , :class => "PactBroker::Webhooks::LatestTriggeredWebhook" , primary_key : :pact_publication_id , key : :pact_publication_id )
10
10
associate ( :one_to_many , :webhooks , :class => "PactBroker::Webhooks::Webhook" , primary_key : [ :consumer_id , :provider_id ] , key : [ :consumer_id , :provider_id ] )
@@ -14,6 +14,35 @@ class Row < Sequel::Model(:matrix)
14
14
dataset_module do
15
15
include PactBroker ::Repositories ::Helpers
16
16
17
+ def refresh params
18
+ source_view_name = model . table_name . to_s . gsub ( 'materialized_' , '' ) . to_sym
19
+ if params [ :consumer_name ] || params [ :provider_name ]
20
+ criteria = { }
21
+ if params [ :consumer_name ]
22
+ pacticipant = PactBroker ::Domain ::Pacticipant . where ( name_like ( :name , params [ :consumer_name ] ) ) . single_record
23
+ criteria [ :consumer_id ] = pacticipant . id if pacticipant
24
+ end
25
+
26
+ if params [ :provider_name ]
27
+ pacticipant = PactBroker ::Domain ::Pacticipant . where ( name_like ( :name , params [ :provider_name ] ) ) . single_record
28
+ criteria [ :provider_id ] = pacticipant . id if pacticipant
29
+ end
30
+ if criteria . any?
31
+ db [ model . table_name ] . where ( criteria ) . delete
32
+ db [ model . table_name ] . insert ( db [ source_view_name ] . where ( criteria ) )
33
+ end
34
+ end
35
+
36
+ if params [ :pacticipant_name ]
37
+ pacticipant = PactBroker ::Domain ::Pacticipant . where ( name_like ( :name , params [ :pacticipant_name ] ) ) . single_record
38
+ if pacticipant
39
+ db [ model . table_name ] . where ( consumer_id : pacticipant . id ) . or ( provider_id : pacticipant . id ) . delete
40
+ new_rows = db [ source_view_name ] . where ( consumer_id : pacticipant . id ) . or ( provider_id : pacticipant . id )
41
+ db [ model . table_name ] . insert ( new_rows )
42
+ end
43
+ end
44
+ end
45
+
17
46
def matching_selectors selectors
18
47
if selectors . size == 1
19
48
where_consumer_or_provider_is ( selectors . first )
0 commit comments