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
This commit is contained in:
Paul Chavard 2021-03-11 12:32:08 +01:00
parent 21d5da379f
commit d24ee27cac
2 changed files with 3 additions and 3 deletions

View file

@ -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?

View file

@ -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