tenseleyflow/shithub / 75eb88f

Browse files

S28: regenerate sqlc — last_indexed_oid + reconciler queries

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
75eb88fc8aa670c6b4a70518e146d7673c13916e
Parents
e54e752
Tree
dca5436

12 changed files

StatusFile+-
M internal/auth/policy/sqlc/models.go 35 0
M internal/checks/sqlc/models.go 35 0
M internal/issues/sqlc/models.go 35 0
M internal/meta/sqlc/models.go 35 0
M internal/pulls/sqlc/models.go 35 0
M internal/repos/queries/repos.sql 29 5
M internal/repos/sqlc/models.go 35 0
M internal/repos/sqlc/querier.go 9 0
M internal/repos/sqlc/repos.sql.go 78 5
M internal/social/sqlc/models.go 35 0
M internal/users/sqlc/models.go 35 0
M internal/worker/sqlc/models.go 35 0
internal/auth/policy/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/checks/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/issues/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/meta/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/pulls/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/repos/queries/repos.sqlmodified
@@ -12,7 +12,8 @@ RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
1212
           disk_used_bytes, fork_of_repo_id, license_key, primary_language,
1313
           has_issues, has_pulls, created_at, updated_at, default_branch_oid,
1414
           allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
15
-          star_count, watcher_count, fork_count, init_status;
15
+          star_count, watcher_count, fork_count, init_status,
16
+          last_indexed_oid;
1617
 
1718
 -- name: GetRepoByID :one
1819
 SELECT id, owner_user_id, owner_org_id, name, description, visibility,
@@ -20,7 +21,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility,
2021
        disk_used_bytes, fork_of_repo_id, license_key, primary_language,
2122
        has_issues, has_pulls, created_at, updated_at, default_branch_oid,
2223
        allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
23
-       star_count, watcher_count, fork_count, init_status
24
+       star_count, watcher_count, fork_count, init_status,
25
+       last_indexed_oid
2426
 FROM repos
2527
 WHERE id = $1;
2628
 
@@ -39,7 +41,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility,
3941
        disk_used_bytes, fork_of_repo_id, license_key, primary_language,
4042
        has_issues, has_pulls, created_at, updated_at, default_branch_oid,
4143
        allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
42
-       star_count, watcher_count, fork_count, init_status
44
+       star_count, watcher_count, fork_count, init_status,
45
+       last_indexed_oid
4346
 FROM repos
4447
 WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL;
4548
 
@@ -55,7 +58,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility,
5558
        disk_used_bytes, fork_of_repo_id, license_key, primary_language,
5659
        has_issues, has_pulls, created_at, updated_at, default_branch_oid,
5760
        allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
58
-       star_count, watcher_count, fork_count, init_status
61
+       star_count, watcher_count, fork_count, init_status,
62
+       last_indexed_oid
5963
 FROM repos
6064
 WHERE owner_user_id = $1 AND deleted_at IS NULL
6165
 ORDER BY updated_at DESC;
@@ -107,7 +111,27 @@ RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
107111
           disk_used_bytes, fork_of_repo_id, license_key, primary_language,
108112
           has_issues, has_pulls, created_at, updated_at, default_branch_oid,
109113
           allow_squash_merge, allow_rebase_merge, allow_merge_commit, default_merge_method,
110
-          star_count, watcher_count, fork_count, init_status;
114
+          star_count, watcher_count, fork_count, init_status,
115
+          last_indexed_oid;
116
+
117
+-- name: SetLastIndexedOID :exec
118
+-- S28 code-search: the worker writes the OID it finished indexing
119
+-- so the reconciler can detect drift (default_branch_oid moved but
120
+-- last_indexed_oid lagged).
121
+UPDATE repos SET last_indexed_oid = sqlc.narg(last_indexed_oid)::text WHERE id = $1;
122
+
123
+-- name: ListReposNeedingReindex :many
124
+-- S28 code-search reconciler: returns repos whose default_branch_oid
125
+-- has advanced past last_indexed_oid (or last_indexed_oid is NULL
126
+-- and a default exists). Limited so a single tick of the cron
127
+-- doesn't try to re-index the whole world.
128
+SELECT id, name, default_branch, default_branch_oid
129
+FROM repos
130
+WHERE deleted_at IS NULL
131
+  AND default_branch_oid IS NOT NULL
132
+  AND (last_indexed_oid IS NULL OR last_indexed_oid <> default_branch_oid)
133
+ORDER BY id
134
+LIMIT $1;
111135
 
112136
 -- name: SetRepoInitStatus :exec
113137
 -- Promotes a fork from init_pending to initialized (or init_failed).
internal/repos/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/repos/sqlc/querier.gomodified
@@ -79,6 +79,11 @@ type Querier interface {
7979
 	// knob later, change this to a parameter.
8080
 	ListRepoIDsPastSoftDeleteGrace(ctx context.Context, db DBTX) ([]int64, error)
8181
 	ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]Repo, error)
82
+	// S28 code-search reconciler: returns repos whose default_branch_oid
83
+	// has advanced past last_indexed_oid (or last_indexed_oid is NULL
84
+	// and a default exists). Limited so a single tick of the cron
85
+	// doesn't try to re-index the whole world.
86
+	ListReposNeedingReindex(ctx context.Context, db DBTX, limit int32) ([]ListReposNeedingReindexRow, error)
8287
 	// /settings/repositories/restore page lists these.
8388
 	ListSoftDeletedReposForOwner(ctx context.Context, db DBTX, ownerUserID pgtype.Int8) ([]ListSoftDeletedReposForOwnerRow, error)
8489
 	// Sender / repo-settings view.
@@ -99,6 +104,10 @@ type Querier interface {
99104
 	// redirect row is INSERTed in the same tx.
100105
 	RenameRepo(ctx context.Context, db DBTX, arg RenameRepoParams) error
101106
 	RestoreRepo(ctx context.Context, db DBTX, id int64) error
107
+	// S28 code-search: the worker writes the OID it finished indexing
108
+	// so the reconciler can detect drift (default_branch_oid moved but
109
+	// last_indexed_oid lagged).
110
+	SetLastIndexedOID(ctx context.Context, db DBTX, arg SetLastIndexedOIDParams) error
102111
 	// Promotes a fork from init_pending to initialized (or init_failed).
103112
 	// The DB row is created up-front so the URL resolves immediately and
104113
 	// the user sees a "preparing your fork" placeholder while the worker
internal/repos/sqlc/repos.sql.gomodified
@@ -48,7 +48,8 @@ RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
4848
           disk_used_bytes, fork_of_repo_id, license_key, primary_language,
4949
           has_issues, has_pulls, created_at, updated_at, default_branch_oid,
5050
           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
5253
 `
5354
 
5455
 type CreateForkRepoParams struct {
@@ -105,6 +106,7 @@ func (q *Queries) CreateForkRepo(ctx context.Context, db DBTX, arg CreateForkRep
105106
 		&i.WatcherCount,
106107
 		&i.ForkCount,
107108
 		&i.InitStatus,
109
+		&i.LastIndexedOid,
108110
 	)
109111
 	return i, err
110112
 }
@@ -122,7 +124,8 @@ RETURNING id, owner_user_id, owner_org_id, name, description, visibility,
122124
           disk_used_bytes, fork_of_repo_id, license_key, primary_language,
123125
           has_issues, has_pulls, created_at, updated_at, default_branch_oid,
124126
           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
126129
 `
127130
 
128131
 type CreateRepoParams struct {
@@ -177,6 +180,7 @@ func (q *Queries) CreateRepo(ctx context.Context, db DBTX, arg CreateRepoParams)
177180
 		&i.WatcherCount,
178181
 		&i.ForkCount,
179182
 		&i.InitStatus,
183
+		&i.LastIndexedOid,
180184
 	)
181185
 	return i, err
182186
 }
@@ -206,7 +210,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility,
206210
        disk_used_bytes, fork_of_repo_id, license_key, primary_language,
207211
        has_issues, has_pulls, created_at, updated_at, default_branch_oid,
208212
        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
210215
 FROM repos
211216
 WHERE id = $1
212217
 `
@@ -242,6 +247,7 @@ func (q *Queries) GetRepoByID(ctx context.Context, db DBTX, id int64) (Repo, err
242247
 		&i.WatcherCount,
243248
 		&i.ForkCount,
244249
 		&i.InitStatus,
250
+		&i.LastIndexedOid,
245251
 	)
246252
 	return i, err
247253
 }
@@ -252,7 +258,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility,
252258
        disk_used_bytes, fork_of_repo_id, license_key, primary_language,
253259
        has_issues, has_pulls, created_at, updated_at, default_branch_oid,
254260
        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
256263
 FROM repos
257264
 WHERE owner_user_id = $1 AND name = $2 AND deleted_at IS NULL
258265
 `
@@ -293,6 +300,7 @@ func (q *Queries) GetRepoByOwnerUserAndName(ctx context.Context, db DBTX, arg Ge
293300
 		&i.WatcherCount,
294301
 		&i.ForkCount,
295302
 		&i.InitStatus,
303
+		&i.LastIndexedOid,
296304
 	)
297305
 	return i, err
298306
 }
@@ -466,7 +474,8 @@ SELECT id, owner_user_id, owner_org_id, name, description, visibility,
466474
        disk_used_bytes, fork_of_repo_id, license_key, primary_language,
467475
        has_issues, has_pulls, created_at, updated_at, default_branch_oid,
468476
        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
470479
 FROM repos
471480
 WHERE owner_user_id = $1 AND deleted_at IS NULL
472481
 ORDER BY updated_at DESC
@@ -509,6 +518,7 @@ func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserI
509518
 			&i.WatcherCount,
510519
 			&i.ForkCount,
511520
 			&i.InitStatus,
521
+			&i.LastIndexedOid,
512522
 		); err != nil {
513523
 			return nil, err
514524
 		}
@@ -520,6 +530,69 @@ func (q *Queries) ListReposForOwnerUser(ctx context.Context, db DBTX, ownerUserI
520530
 	return items, nil
521531
 }
522532
 
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
+
523596
 const setRepoInitStatus = `-- name: SetRepoInitStatus :exec
524597
 UPDATE repos SET init_status = $2 WHERE id = $1
525598
 `
internal/social/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/users/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64
internal/worker/sqlc/models.gomodified
@@ -860,6 +860,21 @@ type CheckSuite struct {
860860
 	UpdatedAt  pgtype.Timestamptz
861861
 }
862862
 
863
+type CodeSearchContent struct {
864
+	RepoID      int64
865
+	RefName     string
866
+	Path        string
867
+	ContentTsv  interface{}
868
+	ContentTrgm string
869
+}
870
+
871
+type CodeSearchPath struct {
872
+	RepoID  int64
873
+	RefName string
874
+	Path    string
875
+	Tsv     interface{}
876
+}
877
+
863878
 type DomainEvent struct {
864879
 	ID          int64
865880
 	ActorUserID pgtype.Int8
@@ -948,6 +963,15 @@ type IssueReference struct {
948963
 	CreatedAt      pgtype.Timestamptz
949964
 }
950965
 
966
+type IssuesSearch struct {
967
+	IssueID      int64
968
+	RepoID       int64
969
+	Kind         IssueKind
970
+	State        IssueState
971
+	AuthorUserID pgtype.Int8
972
+	Tsv          interface{}
973
+}
974
+
951975
 type Job struct {
952976
 	ID          int64
953977
 	Kind        string
@@ -1128,6 +1152,7 @@ type Repo struct {
11281152
 	WatcherCount       int64
11291153
 	ForkCount          int64
11301154
 	InitStatus         RepoInitStatus
1155
+	LastIndexedOid     pgtype.Text
11311156
 }
11321157
 
11331158
 type RepoCollaborator struct {
@@ -1166,6 +1191,11 @@ type RepoTransferRequest struct {
11661191
 	CanceledAt      pgtype.Timestamptz
11671192
 }
11681193
 
1194
+type ReposSearch struct {
1195
+	RepoID int64
1196
+	Tsv    interface{}
1197
+}
1198
+
11691199
 type Star struct {
11701200
 	UserID    int64
11711201
 	RepoID    int64
@@ -1269,6 +1299,11 @@ type UsernameRedirect struct {
12691299
 	ChangedAt   pgtype.Timestamptz
12701300
 }
12711301
 
1302
+type UsersSearch struct {
1303
+	UserID int64
1304
+	Tsv    interface{}
1305
+}
1306
+
12721307
 type Watch struct {
12731308
 	UserID    int64
12741309
 	RepoID    int64