Skip to content

a8n: Move "default branch" check to execution of CampaignJob

Created by: mrnugget

Current state when creating a new CampaignPlan ("Preview changes"):

  • We open a transaction
  • For each repo the scopeQuery yields we create a CampaignJob
  • For each CampaignJob we ask gitserver for its default branch
  • If gitserver cannot determine a default branch the transaction is rolled back
  • Otherwise: transaction is committed

Here is the code.

That means the transaction is open for the duration of time it takes to ask gitserver for all default branches.

That's not a problem per se, but it is bad UX since it might take a while until the user sees something after hitting the "Preview changes" button.

I propose that we move the determination of a CampaignJobs BaseRef and Rev out of the transaction and set those when actually running the job here.

That would require making rev and base_ref nullable fields in the database and since we have a database unique constraint on (campaign_plan_id, repo_id, rev) we have to find out how that works with NULL fields.

The upsides:

  1. We don't hammer gitserver with possibly hundreds of requests in a tight loop
  2. One request failing won't fail the whole CampaignPlan but instead result in a single errored CampaignJob
  3. The user will get faster feedback when previewing changes because the transaction will be much faster since it's not bound to gitserver anymore