Skip to content

Commit 7eac0b3

Browse files
committed
Check if shots exist before mapping them
1 parent 91fac91 commit 7eac0b3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

app/jobs/refresh_token_job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class RefreshTokenJob < ApplicationJob
77

88
def perform(identity)
99
identity.refresh_token!
10+
return unless identity.airtable?
1011

11-
AirtableShotUploadAllJob.set(wait: 2.minutes).perform_later(identity.user) if identity.airtable?
12+
AirtableShotUploadAllJob.set(wait: 2.minutes).perform_later(identity.user)
1213
end
1314
end

app/models/airtable/shots.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ def upload(shot)
2020
if shot.airtable_id
2121
update_record(shot.airtable_id, prepare_record(shot))
2222
else
23-
upload_multiple(::Shot.where(id: shot.id))
23+
upload_multiple(::Shot.where(user:, id: shot.id))
2424
end
2525
end
2626

2727
def upload_multiple(shots)
28-
records = shots.where(user:).with_attached_image.map { |shot| prepare_record(shot) }
28+
return unless shots.exists?
29+
30+
records = shots.with_attached_image.map { |shot| prepare_record(shot) }
2931
update_records(records) do |response|
3032
response["records"].each do |record|
3133
shot = shots.find_by(id: record["fields"]["ID"])

0 commit comments

Comments
 (0)