First job of a repost chain
TL;DR
- Each reposted job stores the
idof the first job of its repost chain in the new columnjod_jobs.original_job_id. - A job that was never reposted keeps
jod_jobs.original_job_idempty, 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\JodJobhides the column, so no job API returns it.
Words used in this doc
| Word | Meaning |
|---|---|
The table jod_jobs | The jobs that a company posts, one row per job, with the model App\Entities\JodJob |
| Repost | The backend copies a job with replicate() and saves the copy as a new open job |
The column jod_jobs.prev_job_id | The id of the job that this job was copied from, one step back |
| Repost chain | All jobs that come from one first job, such as A, B, C and D |
| First job | The job at the start of a repost chain, which was not copied from another job |
The repository PORTAL_V2_BACKEND_GLOBAL | The 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
- A company posts Job A.
- An applicant cancels, and the backend reposts Job A as Job B.
- Job B is reposted as Job C, then Job C as Job D.
- Job D remembers only Job C.
- The applicants of Jobs A, B and C cancelled, and the worker of Job D completes the work.
- A report shows four jobs: three cancelled and one completed.
- The company asked for one job, so the report should show one job.
- 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.
| Measure | Value |
|---|---|
| Jobs in total | 514,802 |
| Reposts, which are jobs copied from another job | 27,417, the first on 2024-08-14 |
| Reposts one step from their first job | 24,298 |
| Reposts two to five steps from their first job | 3,118 |
| Reposts six steps from their first job, the longest chain | 1 |
| Reposts whose source job is missing from the table | 0 |
| Reposts whose source job is soft-deleted | 0 |
| Time to walk every chain up to its first job in one query | 25.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 counts | Jobs counted today | First jobs |
|---|---|---|
| All jobs | 10,272 | 8,698 |
Jobs with an applicant who cancelled, slot_user.status: 7 | 1,045 | 938 |
Jobs where all applicants cancelled, jod_jobs.status: 11 | 984 | 882 |
Jobs where all applicants were rejected, jod_jobs.status: 10 | 793 | 727 |
Jobs cancelled more than 12 hours before or after the start, jod_jobs.status: 4 | 812 | 810 |
Jobs cancelled within 12 hours of the start, jod_jobs.status: 4 | 79 | 79 |
Jobs with a no-show, slot_user.status: 8 | 209 | 208 |
- 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
| Rule | Applies to | Example |
|---|---|---|
A job that was never reposted keeps jod_jobs.original_job_id empty | always | Job A has original_job_id: NULL |
A copy takes original_job_id from its source job when it has one | US-1 | Job D gets original_job_id: A from Job C |
A copy takes the source id when the source has no original_job_id | US-1 | Job B gets original_job_id: A from Job A |
jod_jobs.prev_job_id keeps its meaning, one step back | always | Job D keeps prev_job_id: C |
jod_jobs.original_job_id never changes after the copy is saved | always | Job 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 job | US-1, US-2 | COALESCE(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
- Job A is posted with
prev_job_id: NULLandoriginal_job_id: NULL. - The backend reposts Job A as Job B.
- Job A has no
original_job_id, so Job B getsoriginal_job_id: Aandprev_job_id: A.
- Job A has no
- The backend reposts Job B as Job C.
- Job B has
original_job_id: A, so Job C getsoriginal_job_id: Aandprev_job_id: B.
- Job B has
- The backend reposts Job C as Job D, which gets
original_job_id: Aandprev_job_id: C. - A report reads
D.original_job_idand 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.
| Column | Type | Meaning |
|---|---|---|
jod_jobs.original_job_id | unsignedBigInteger, nullable, after prev_job_id | The id of the first job of the repost chain, empty for a first job |
| Foreign key | Column | References | On delete |
|---|---|---|---|
jod_jobs_original_job_id_foreign | original_job_id | jod_jobs.id | The default, which blocks the delete |
The foreign key stops a value that is not a job from reaching the column.
jod_jobs.idisbigIncrements, so the column typeunsignedBigIntegermatches 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_postingon 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.
- No path in the backend hard-deletes a job today, because the model uses
- 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 place | File | Entry point | Trigger |
|---|---|---|---|
| Repost a job | app/Services/JodJobService.php | repostJob | An applicant cancels, an admin disables an applicant, or future jobs are cancelled |
| Repost one slot | app/Services/JodJobService.php | repostSingleSlot | An applicant cancels one slot |
| Auto job posting | app/Console/Commands/JodJobAutoJobPostingCommand.php | handle | The cron command:auto_job_posting |
| Auto multiple-day job posting | app/Console/Commands/JodJobAutoMultipleDayJobPostingCommand.php | handle | The cron command:auto_job_posting_multiple_day |
| Job repost command | app/Console/Commands/JodJobRepostCommand.php | handle | The 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 has | The method returns |
|---|---|
A value in original_job_id | That value |
No original_job_id and no prev_job_id | The source id, because the source is a first job |
No original_job_id, but a prev_job_id | The 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
## Rolloutfinishes. - 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_idpoints to a missing row, and returns that job'sid.
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\JodJobdeclares no$hiddenlist today. - So every endpoint that returns the model as JSON shows every column,
prev_job_idincluded. - 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$hiddenlist, so each call must start fromJodJob::getDefaultHidden().- Four calls passed a fixed list, two in
app/Services/JodJobService.phpand two inapp/Services/V1/JodJobService.php.- They now start from
JodJob::getDefaultHidden(), and a test refuses a fixed list.
- They now start from
getDefaultHidden()returns the model$hiddenlist, sooriginal_job_idstays 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
| Option | How it works | Why it lost |
|---|---|---|
Keep only jod_jobs.prev_job_id | Each report walks the chain with a recursive query | The walk takes 25.6 seconds today, and every report repeats it |
A first job stores its own id in original_job_id | Every job gets a value, so a report needs no COALESCE | Every place that creates a job must write a second time, after the insert gives the id |
An index only on jod_jobs.original_job_id | The database accepts any number in the column | A 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 APIs | The APP and the Portal can read the first job | No screen needs it, and reports read the database directly |
| A new table of repost chains | One row per chain, with the first job and the count | jod_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 readsprev_job_idand is turned off inapp/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.
MonthlyBusinessReportExportinPORTAL_V2_REPORTcounts cancellations and no-shows today.
Rollout
- Ship the migration for the column and the index, with the method and the five repost places, in one release.
- Run the fill command with
--dry-run, and a software engineer reads the report. - Run the fill command for real.
- Run the fill command with
--dry-runagain, 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
idorder, from small to large, in batches of 1,000. - Every repost has a smaller
prev_job_idthan its ownid, 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_idalready, the nearest one gives the value. - It writes with
DB::table('jod_jobs'), so the modelApp\Entities\JodJobwrites no audit row and keepsupdated_at. - It reads soft-deleted jobs too, because
DB::tabledoes 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 is | The command does |
|---|---|
Soft-deleted, with deleted_at set | It reads the row as usual, so the chain stays whole |
| Missing from the table | It 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_idand the neworiginal_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_idthat points to a job with aprev_job_id, and expects 0.
After release
| What we watch | How often | Who |
|---|---|---|
Reposts created with prev_job_id and no original_job_id, 27,417 today | Daily for two weeks | Software engineer |
Reposts whose original_job_id points to a job that has a prev_job_id | Weekly for one month | Software engineer |