lib/pact_broker/matrix/row.rb in pact_broker-2.16.1 vs lib/pact_broker/matrix/row.rb in pact_broker-2.17.0

- old
+ new

@@ -17,45 +17,33 @@ dataset_module do include PactBroker::Repositories::Helpers include PactBroker::Logging - def refresh params - logger.debug("Refreshing #{model.table_name} for #{params}") + def refresh ids + logger.debug("Refreshing #{model.table_name} for #{ids}") db = model.db table_name = model.table_name - source_view_name = model.table_name.to_s.gsub('materialized_', '').to_sym - if params[:consumer_name] || params[:provider_name] - criteria = {} - if params[:consumer_name] - pacticipant = PactBroker::Domain::Pacticipant.where(name_like(:name, params[:consumer_name])).single_record - criteria[:consumer_id] = pacticipant.id if pacticipant + if ids[:pacticipant_id] + db.transaction do + db[table_name].where(consumer_id: ids[:pacticipant_id]).or(provider_id: ids[:pacticipant_id]).delete + new_rows = db[source_view_name].where(consumer_id: ids[:pacticipant_id]).or(provider_id: ids[:pacticipant_id]).distinct + db[table_name].insert(new_rows) end - - if params[:provider_name] - pacticipant = PactBroker::Domain::Pacticipant.where(name_like(:name, params[:provider_name])).single_record - criteria[:provider_id] = pacticipant.id if pacticipant + elsif ids.any? + accepted_columns = [:consumer_id, :consumer_name, :provider_id, :provider_name] + criteria = ids.reject{ |k, v| !accepted_columns.include?(k) } + db.transaction do + db[table_name].where(criteria).delete + db[table_name].insert(db[source_view_name].where(criteria)) end - if criteria.any? - db.transaction do - db[table_name].where(criteria).delete - db[table_name].insert(db[source_view_name].where(criteria).distinct) - end - end end + end - if params[:pacticipant_name] - pacticipant = PactBroker::Domain::Pacticipant.where(name_like(:name, params[:pacticipant_name])).single_record - if pacticipant - db.transaction do - db[table_name].where(consumer_id: pacticipant.id).or(provider_id: pacticipant.id).delete - new_rows = db[source_view_name].where(consumer_id: pacticipant.id).or(provider_id: pacticipant.id).distinct - db[table_name].insert(new_rows) - end - end - end + def source_view_name + model.table_name.to_s.gsub('materialized_', '').to_sym end def matching_selectors selectors if selectors.size == 1 where_consumer_or_provider_is(selectors.first)