Skip to main content

First job of a repost chain

TL;DR​

  • Each reposted job stores the id of the first job of its repost chain in the new column jod_jobs.original_job_id.
  • A job that was never reposted keeps jod_jobs.original_job_id empty, so only the five repost places change.
  • The column gets a foreign key to jod_jobs.id, which also gives it an index.
  • One command fills the 27,417 reposts that exist today, with a dry run first.
  • The model App\Entities\JodJob hides the column, so no job API returns it.

Words used in this doc​

WordMeaning
The table jod_jobsThe jobs that a company posts, one row per job, with the model App\Entities\JodJob
RepostThe backend copies a job with replicate() and saves the copy as a new open job
The column jod_jobs.prev_job_idThe id of the job that this job was copied from, one step back
Repost chainAll jobs that come from one first job, such as A, B, C and D
First jobThe job at the start of a repost chain, which was not copied from another job
The repository PORTAL_V2_BACKEND_GLOBALThe JodGig PHP backend, where all five repost places live

Problem​

Reports count one job many times, because each repost counts as a separate job.

  • One job that is cancelled, reposted and then completed is one piece of work for the company.
  • A report counts it as two jobs, one cancelled and one completed.
  • The same happens for jobs that applicants cancelled, and for jobs where the company rejected the worker.
  • Each repost remembers only the job it was copied from, one step back.
    • So a report must read every job in between to reach the first job, which is slow.
  • The goal is that each reposted job names its first job directly, so a report can count that job once.

Worked example: Job A reposted three times​

  1. A company posts Job A.
  2. An applicant cancels, and the backend reposts Job A as Job B.
  3. Job B is reposted as Job C, then Job C as Job D.
  4. Job D remembers only Job C.
  5. The applicants of Jobs A, B and C cancelled, and the worker of Job D completes the work.
  6. A report shows four jobs: three cancelled and one completed.
  7. The company asked for one job, so the report should show one job.
  8. To find Job A from Job D, a report reads Job C, then Job B, then Job A.

What the data shows​

The counts come from the data copy jodgig_ai, read on 2026-11-19.

MeasureValue
Jobs in total514,802
Reposts, which are jobs copied from another job27,417, the first on 2024-08-14
Reposts one step from their first job24,298
Reposts two to five steps from their first job3,118
Reposts six steps from their first job, the longest chain1
Reposts whose source job is missing from the table0
Reposts whose source job is soft-deleted0
Time to walk every chain up to its first job in one query25.6 seconds, against a limit of 30 seconds

The next counts cover jobs that start in October 2026, read on 2026-11-23.

What a report countsJobs counted todayFirst jobs
All jobs10,2728,698
Jobs with an applicant who cancelled, slot_user.status: 71,045938
Jobs where all applicants cancelled, jod_jobs.status: 11984882
Jobs where all applicants were rejected, jod_jobs.status: 10793727
Jobs cancelled more than 12 hours before or after the start, jod_jobs.status: 4812810
Jobs cancelled within 12 hours of the start, jod_jobs.status: 47979
Jobs with a no-show, slot_user.status: 8209208
  • Reposts add 1,574 jobs to the total, which is 18% more than the first jobs.
  • Of the 882 first jobs where all applicants cancelled, 367 also have a completed job in the chain.
  • Of the 727 first jobs where all applicants were rejected, 332 also have a completed job in the chain.
  • The last three rows hardly change, because few of those jobs share a chain.
  • Most chains are short, so one pass over the reposts can fill the new column.
  • The walk is close to the query limit already, so a report cannot do it each time.

Context​

The backend reposts a job when the job loses its worker and still has time to fill.

  • An applicant cancels, an admin disables an applicant, or the company cancels future slots.
  • Two scheduled commands also repost open jobs automatically.
  • Cancellation Policy Improvement holds the cancellation rules that lead to a repost.

A repost is a full copy of the source job, with new slots, a new billing and a new id.

  • The copy starts as an open job with no applicants.
  • The source job stays in the table with its own status.

User stories​

  • US-1: As product, I want every repost of one job in one group, so a report counts that job once.
  • US-2: As a report engineer, I want the first job in one column, so my query stays fast.

Rules​

RuleApplies toExample
A job that was never reposted keeps jod_jobs.original_job_id emptyalwaysJob A has original_job_id: NULL
A copy takes original_job_id from its source job when it has oneUS-1Job D gets original_job_id: A from Job C
A copy takes the source id when the source has no original_job_idUS-1Job B gets original_job_id: A from Job A
jod_jobs.prev_job_id keeps its meaning, one step backalwaysJob D keeps prev_job_id: C
jod_jobs.original_job_id never changes after the copy is savedalwaysJob D keeps original_job_id: A when Job C is cancelled
A report groups a chain by original_job_id, or by id for the first jobUS-1, US-2COALESCE(original_job_id, id) is A for jobs A, B, C and D

Direction​

Each repost writes the first job of its chain next to the job it was copied from.

  • Nothing changes for a company, an applicant or OPS.
  • Reports read one column instead of walking the chain.

Worked example: Job A reposted three times, after the change​

  1. Job A is posted with prev_job_id: NULL and original_job_id: NULL.
  2. The backend reposts Job A as Job B.
    • Job A has no original_job_id, so Job B gets original_job_id: A and prev_job_id: A.
  3. The backend reposts Job B as Job C.
    • Job B has original_job_id: A, so Job C gets original_job_id: A and prev_job_id: B.
  4. The backend reposts Job C as Job D, which gets original_job_id: A and prev_job_id: C.
  5. A report reads D.original_job_id and finds Job A in one step.

Database​

One column and one foreign key go on the table jod_jobs, next to jod_jobs.prev_job_id.

ColumnTypeMeaning
jod_jobs.original_job_idunsignedBigInteger, nullable, after prev_job_idThe id of the first job of the repost chain, empty for a first job
Foreign keyColumnReferencesOn delete
jod_jobs_original_job_id_foreignoriginal_job_idjod_jobs.idThe default, which blocks the delete

The foreign key stops a value that is not a job from reaching the column.

  • jod_jobs.id is bigIncrements, so the column type unsignedBigInteger matches it.
  • MySQL builds an index for the foreign key.
    • So a report finds every job of one chain without reading the whole table.
  • The foreign key check takes a shared lock on the first job when a copy is saved.
    • Two reposts of one job at the same time would deadlock if each then updates the source job.
    • So the two methods and the two active crons set is_auto_job_posting on the source before they save the copy.
  • A hard delete of a first job fails while a copy points to it.
    • No path in the backend hard-deletes a job today, because the model uses SoftDeletes.
  • MySQL rebuilds the table to add a foreign key while foreign key checks are on.
    • So the migration runs outside peak hours.

Backend​

One new method on the model App\Entities\JodJob returns the value for a copy, and all five repost places call it.

Repost placeFileEntry pointTrigger
Repost a jobapp/Services/JodJobService.phprepostJobAn applicant cancels, an admin disables an applicant, or future jobs are cancelled
Repost one slotapp/Services/JodJobService.phprepostSingleSlotAn applicant cancels one slot
Auto job postingapp/Console/Commands/JodJobAutoJobPostingCommand.phphandleThe cron command:auto_job_posting
Auto multiple-day job postingapp/Console/Commands/JodJobAutoMultipleDayJobPostingCommand.phphandleThe cron command:auto_job_posting_multiple_day
Job repost commandapp/Console/Commands/JodJobRepostCommand.phphandleThe cron command:job-repost, turned off in app/Console/Kernel.php

Each place copies the job with replicate(), then sets prev_job_id to the source id.

# app/Services/JodJobService.php:1652-1754
public function repostJob($job, $userId, $cancelledSlots = null, $canceledSlot = null, $isSuspended = false)
# ...
$cloneJob = $job->replicate();
# ...
$cloneJob->prev_job_id = $job->id;
$cloneJob->save();

replicate() copies every column except id, created_at and updated_at.

  • So a copy already carries the source original_job_id.
  • A copy of a first job carries NULL, which is wrong, so each place sets the value on purpose.
# vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1566-1572
public function replicate(array $except = null)
{
$defaults = [
$this->getKeyName(),
$this->getCreatedAtColumn(),
$this->getUpdatedAtColumn(),

The new method JodJob::originalJobIdForCopy() decides the value in three cases.

The source job hasThe method returns
A value in original_job_idThat value
No original_job_id and no prev_job_idThe source id, because the source is a first job
No original_job_id, but a prev_job_idThe first job found by walking prev_job_id, because the source is an old repost that the fill command has not reached
  • The third case exists only until the fill command in ## Rollout finishes.
  • The walk reads soft-deleted jobs too, so a deleted job in the middle does not stop it.
  • The walk stops at a job whose prev_job_id points to a missing row, and returns that job's id.

Each place sets the column on the line after prev_job_id.

$cloneJob->prev_job_id = $job->id;
$cloneJob->original_job_id = $job->originalJobIdForCopy();
$cloneJob->save();

APIs​

No job API returns jod_jobs.original_job_id, because only reports need it.

  • The model App\Entities\JodJob declares no $hidden list today.
  • So every endpoint that returns the model as JSON shows every column, prev_job_id included.
  • 35 queries in the backend select jod_jobs.*, so a list of endpoints would miss some.
  • So the model hides the column once, and no endpoint needs a change.
protected $hidden = ['original_job_id'];

The endpoints that hide more fields must keep the new column hidden too.

  • JodJob::setStaticHidden() replaces the model $hidden list, so each call must start from JodJob::getDefaultHidden().
  • Four calls passed a fixed list, two in app/Services/JodJobService.php and two in app/Services/V1/JodJobService.php.
    • They now start from JodJob::getDefaultHidden(), and a test refuses a fixed list.
  • getDefaultHidden() returns the model $hidden list, so original_job_id stays in it.
  • No code calls JodJob::setStaticVisible(), which is the one call that ignores $hidden.
# app/Repositories/JodJobRepositoryEloquent.php:89-91
$hiddenFields = JodJob::getDefaultHidden();
$hiddenFields = array_merge($hiddenFields, JodJob::getStaticAppends());
JodJob::setStaticHidden($hiddenFields);

$hidden changes only the JSON output, so replicate(), DB::table and reports still read the column.

Rejected options​

OptionHow it worksWhy it lost
Keep only jod_jobs.prev_job_idEach report walks the chain with a recursive queryThe walk takes 25.6 seconds today, and every report repeats it
A first job stores its own id in original_job_idEvery job gets a value, so a report needs no COALESCEEvery place that creates a job must write a second time, after the insert gives the id
An index only on jod_jobs.original_job_idThe database accepts any number in the columnA wrong value from the fill command or a repost place would stay in the column with no error
Return original_job_id in the job APIsThe APP and the Portal can read the first jobNo screen needs it, and reports read the database directly
A new table of repost chainsOne row per chain, with the first job and the countjod_jobs already holds one row per job, so the table would repeat it

Out of scope​

  • An index on jod_jobs.prev_job_id, which is a separate change if a report needs it.
  • Showing the repost chain to a company or to OPS in the Portal.
  • The command command:auto_job_posting_all_user_notification, which reads prev_job_id and is turned off in app/Console/Kernel.php.

Open questions​

  • Which result does a report show for a chain that has both cancelled and completed jobs?
    • Proposed, not discussed: a report of jobs uses the last job, and a report of cancellations counts every cancellation.
  • Which reports change to count by first job, and who changes them?
    • The column alone changes no report number.
    • MonthlyBusinessReportExport in PORTAL_V2_REPORT counts cancellations and no-shows today.

Rollout​

  1. Ship the migration for the column and the index, with the method and the five repost places, in one release.
  2. Run the fill command with --dry-run, and a software engineer reads the report.
  3. Run the fill command for real.
  4. Run the fill command with --dry-run again, and the report shows 0 reposts that can be filled and 0 over the limit.

Existing records​

The new command command:backfill-original-job-id fills every repost that has prev_job_id and no original_job_id.

  • It reads the reposts in id order, from small to large, in batches of 1,000.
  • Every repost has a smaller prev_job_id than its own id, with 0 exceptions on 2026-11-23.
  • For each batch, it loads the reposts and every job above them, one step of all chains per query.
  • It finds the first job by walking prev_job_id, and not from the values written so far.
    • So a dry run and a live run find the same first job.
  • When a job above the repost has an original_job_id already, the nearest one gives the value.
  • It writes with DB::table('jod_jobs'), so the model App\Entities\JodJob writes no audit row and keeps updated_at.
  • It reads soft-deleted jobs too, because DB::table does not apply the soft-delete filter.
  • First jobs keep original_job_id: NULL, so the command never touches them.
  • A run can stop and start again, because it fills only rows that are still empty.

A chain with a deleted job follows two rules.

The source job isThe command does
Soft-deleted, with deleted_at setIt reads the row as usual, so the chain stays whole
Missing from the tableIt sets original_job_id to the oldest job of the chain that still exists, and lists the row in the report
  • No repost points to a missing or soft-deleted job today, so both rows are a guard.
  • A chain longer than 50 steps stops the walk and goes in the report, because the longest today is 6.

Dry run​

The command with --dry-run writes nothing and prints one report.

  • The number of reposts that can be filled, 27,417 on 2026-11-19, without the chains over the limit.
  • The number per chain length, which should match ### What the data shows.
  • Every repost whose source job is missing, expected 0.
  • Every chain that hit the 50-step limit, expected 0.
  • 20 sample rows with id, prev_job_id and the new original_job_id, for the engineer to check by hand.

After the live run, the same report shows 0 reposts that can be filled, and 0 over the limit.

  • A second check finds every original_job_id that points to a job with a prev_job_id, and expects 0.

After release​

What we watchHow oftenWho
Reposts created with prev_job_id and no original_job_id, 27,417 todayDaily for two weeksSoftware engineer
Reposts whose original_job_id points to a job that has a prev_job_idWeekly for one monthSoftware engineer