@@ -48,7 +48,8 @@ RETURNING id, owner_user_id, owner_org_id, name, description, visibility, |
| 48 | 48 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 49 | 49 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 50 | 50 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 51 | | - star_count, watcher_count, fork_count, init_status |
| 51 | + star_count, watcher_count, fork_count, init_status, |
| 52 | + last_indexed_oid |
| 52 | 53 | ` |
| 53 | 54 | |
| 54 | 55 | type CreateForkRepoParams struct { |
@@ -105,6 +106,7 @@ func (q *Queries) CreateForkRepo(ctx context.Context, db DBTX, arg CreateForkRep |
| 105 | 106 | &i.WatcherCount, |
| 106 | 107 | &i.ForkCount, |
| 107 | 108 | &i.InitStatus, |
| 109 | + &i.LastIndexedOid, |
| 108 | 110 | ) |
| 109 | 111 | return i, err |
| 110 | 112 | } |
@@ -122,7 +124,8 @@ RETURNING id, owner_user_id, owner_org_id, name, description, visibility, |
| 122 | 124 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 123 | 125 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 124 | 126 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 125 | | - star_count, watcher_count, fork_count, init_status |
| 127 | + star_count, watcher_count, fork_count, init_status, |
| 128 | + last_indexed_oid |
| 126 | 129 | ` |
| 127 | 130 | |
| 128 | 131 | type CreateRepoParams struct { |
@@ -177,6 +180,7 @@ func (q *Queries) CreateRepo(ctx context.Context, db DBTX, arg CreateRepoParams) |
| 177 | 180 | &i.WatcherCount, |
| 178 | 181 | &i.ForkCount, |
| 179 | 182 | &i.InitStatus, |
| 183 | + &i.LastIndexedOid, |
| 180 | 184 | ) |
| 181 | 185 | return i, err |
| 182 | 186 | } |
@@ -206,7 +210,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 206 | 210 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 207 | 211 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 208 | 212 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 209 | | - star_count, watcher_count, fork_count, init_status |
| 213 | + star_count, watcher_count, fork_count, init_status, |
| 214 | + last_indexed_oid |
| 210 | 215 | FROM repos |
| 211 | 216 | WHERE id = $1 |
| 212 | 217 | ` |
@@ -242,6 +247,7 @@ func (q *Queries) GetRepoByID(ctx context.Context, db DBTX, id int64) (Repo, err |
| 242 | 247 | &i.WatcherCount, |
| 243 | 248 | &i.ForkCount, |
| 244 | 249 | &i.InitStatus, |
| 250 | + &i.LastIndexedOid, |
| 245 | 251 | ) |
| 246 | 252 | return i, err |
| 247 | 253 | } |
@@ -252,7 +258,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 252 | 258 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 253 | 259 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 254 | 260 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 255 | | - star_count, watcher_count, fork_count, init_status |
| 261 | + star_count, watcher_count, fork_count, init_status, |
| 262 | + last_indexed_oid |
| 256 | 263 | FROM repos |
| 257 | 264 | WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL |
| 258 | 265 | ` |
@@ -293,6 +300,7 @@ func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg Ge |
| 293 | 300 | &i.WatcherCount, |
| 294 | 301 | &i.ForkCount, |
| 295 | 302 | &i.InitStatus, |
| 303 | + &i.LastIndexedOid, |
| 296 | 304 | ) |
| 297 | 305 | return i, err |
| 298 | 306 | } |
@@ -466,7 +474,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility, |
| 466 | 474 | disk_used_bytes, fork_of_repo_id, license_key, primary_language, |
| 467 | 475 | has_issues, has_pulls, created_at, updated_at, default_branch_oid, |
| 468 | 476 | allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method, |
| 469 | | - star_count, watcher_count, fork_count, init_status |
| 477 | + star_count, watcher_count, fork_count, init_status, |
| 478 | + last_indexed_oid |
| 470 | 479 | FROM repos |
| 471 | 480 | WHERE owner_user_id = $1 AND deleted_at IS NULL |
| 472 | 481 | ORDER BY updated_at DESC |
@@ -509,6 +518,7 @@ func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserI |
| 509 | 518 | &i.WatcherCount, |
| 510 | 519 | &i.ForkCount, |
| 511 | 520 | &i.InitStatus, |
| 521 | + &i.LastIndexedOid, |
| 512 | 522 | ); err != nil { |
| 513 | 523 | return nil, err |
| 514 | 524 | } |
@@ -520,6 +530,69 @@ func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserI |
| 520 | 530 | return items, nil |
| 521 | 531 | } |
| 522 | 532 | |
| 533 | +const listReposNeedingReindex = `-- name: ListReposNeedingReindex :many |
| 534 | +SELECT id, name, default_branch, default_branch_oid |
| 535 | +FROM repos |
| 536 | +WHERE deleted_at IS NULL |
| 537 | + AND default_branch_oid IS NOT NULL |
| 538 | + AND (last_indexed_oid IS NULL OR last_indexed_oid <> default_branch_oid) |
| 539 | +ORDER BY id |
| 540 | +LIMIT $1 |
| 541 | +` |
| 542 | + |
| 543 | +type ListReposNeedingReindexRow struct { |
| 544 | + ID int64 |
| 545 | + Name string |
| 546 | + DefaultBranch string |
| 547 | + DefaultBranchOid pgtype.Text |
| 548 | +} |
| 549 | + |
| 550 | +// S28 code-search reconciler: returns repos whose default_branch_oid |
| 551 | +// has advanced past last_indexed_oid (or last_indexed_oid is NULL |
| 552 | +// and a default exists). Limited so a single tick of the cron |
| 553 | +// doesn't try to re-index the whole world. |
| 554 | +func (q *Queries) ListReposNeedingReindex(ctx context.Context, db DBTX, limit int32) ([]ListReposNeedingReindexRow, error) { |
| 555 | + rows, err := db.Query(ctx, listReposNeedingReindex, limit) |
| 556 | + if err != nil { |
| 557 | + return nil, err |
| 558 | + } |
| 559 | + defer rows.Close() |
| 560 | + items := []ListReposNeedingReindexRow{} |
| 561 | + for rows.Next() { |
| 562 | + var i ListReposNeedingReindexRow |
| 563 | + if err := rows.Scan( |
| 564 | + &i.ID, |
| 565 | + &i.Name, |
| 566 | + &i.DefaultBranch, |
| 567 | + &i.DefaultBranchOid, |
| 568 | + ); err != nil { |
| 569 | + return nil, err |
| 570 | + } |
| 571 | + items = append(items, i) |
| 572 | + } |
| 573 | + if err := rows.Err(); err != nil { |
| 574 | + return nil, err |
| 575 | + } |
| 576 | + return items, nil |
| 577 | +} |
| 578 | + |
| 579 | +const setLastIndexedOID = `-- name: SetLastIndexedOID :exec |
| 580 | +UPDATE repos SET last_indexed_oid = $2::text WHERE id = $1 |
| 581 | +` |
| 582 | + |
| 583 | +type SetLastIndexedOIDParams struct { |
| 584 | + ID int64 |
| 585 | + LastIndexedOid pgtype.Text |
| 586 | +} |
| 587 | + |
| 588 | +// S28 code-search: the worker writes the OID it finished indexing |
| 589 | +// so the reconciler can detect drift (default_branch_oid moved but |
| 590 | +// last_indexed_oid lagged). |
| 591 | +func (q *Queries) SetLastIndexedOID(ctx context.Context, db DBTX, arg SetLastIndexedOIDParams) error { |
| 592 | + _, err := db.Exec(ctx, setLastIndexedOID, arg.ID, arg.LastIndexedOid) |
| 593 | + return err |
| 594 | +} |
| 595 | + |
| 523 | 596 | const setRepoInitStatus = `-- name: SetRepoInitStatus :exec |
| 524 | 597 | UPDATE repos SET init_status = $2 WHERE id = $1 |
| 525 | 598 | ` |