From 21d5da379f19217817a69056f801e92aad08f5de Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 11 Mar 2021 12:25:47 +0100 Subject: [PATCH 1/2] remove unused job --- app/jobs/annuaire_education_update_job.rb | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 app/jobs/annuaire_education_update_job.rb diff --git a/app/jobs/annuaire_education_update_job.rb b/app/jobs/annuaire_education_update_job.rb deleted file mode 100644 index ffd06a27e..000000000 --- a/app/jobs/annuaire_education_update_job.rb +++ /dev/null @@ -1,16 +0,0 @@ -class AnnuaireEducationUpdateJob < ApplicationJob - def perform(champ) - external_id = champ.external_id - - if external_id.present? - data = APIEducation::AnnuaireEducationAdapter.new(external_id).to_params - - if data.present? - champ.data = data - else - champ.external_id = nil - end - champ.save! - end - end -end From d24ee27cac80801bdd264ce987c158889c27e852 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 11 Mar 2021 12:32:08 +0100 Subject: [PATCH 2/2] Try to reduce the number of external data fetches Only fetch external data if the external_id is the current one and data is not yet fetched --- app/jobs/champ_fetch_external_data_job.rb | 4 ++-- app/models/champ.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/champ_fetch_external_data_job.rb b/app/jobs/champ_fetch_external_data_job.rb index ab8a09f7d..366586dda 100644 --- a/app/jobs/champ_fetch_external_data_job.rb +++ b/app/jobs/champ_fetch_external_data_job.rb @@ -1,6 +1,6 @@ class ChampFetchExternalDataJob < ApplicationJob - def perform(champ) - if champ.external_id.present? + def perform(champ, external_id) + if champ.external_id == external_id && champ.data.nil? data = champ.fetch_external_data if data.present? diff --git a/app/models/champ.rb b/app/models/champ.rb index e2e688021..ef9072e49 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -171,7 +171,7 @@ class Champ < ApplicationRecord def fetch_external_data_later if fetch_external_data? && external_id.present? && data.nil? - ChampFetchExternalDataJob.perform_later(self) + ChampFetchExternalDataJob.perform_later(self, external_id) end end