app/queries/decidim/surveys/metrics/answers_metric_manage.rb in decidim-surveys-0.21.0 vs app/queries/decidim/surveys/metrics/answers_metric_manage.rb in decidim-surveys-0.22.0

- old
+ new

@@ -7,13 +7,10 @@ def metric_name "survey_answers" end def save - return @registry if @registry - - @registry = [] query.each do |key, results| cumulative_value = results[:cumulative] next if cumulative_value.zero? quantity_value = results[:quantity] || 0 @@ -21,14 +18,12 @@ record = Decidim::Metric.find_or_initialize_by(day: @day.to_s, metric_type: @metric_name, organization: @organization, decidim_category_id: nil, participatory_space_type: space_type, participatory_space_id: space_id, related_object_type: Decidim::Surveys::Survey.name, related_object_id: survey_id) record.assign_attributes(cumulative: cumulative_value, quantity: quantity_value) - @registry << record + record.save! end - @registry.each(&:save!) - @registry end private def query @@ -47,11 +42,10 @@ end @query end def retrieve_surveys - components = Decidim::Component.where(participatory_space: retrieve_participatory_spaces).published - Decidim::Surveys::Survey.where(component: components) + Decidim::Surveys::Survey.where(component: visible_component_ids_from_spaces(retrieve_participatory_spaces)) end def retrieve_questionnaires(survey) Decidim::Forms::Questionnaire.includes(:questionnaire_for) .where(questionnaire_for: survey)