@@ -269,23 +269,23 @@ type CommitStatusIndex struct {
269
269
270
270
// GetLatestCommitStatus returns all statuses with a unique context for a given commit.
271
271
func GetLatestCommitStatus (ctx context.Context , repoID int64 , sha string , listOptions db.ListOptions ) ([]* CommitStatus , int64 , error ) {
272
- ids := make ([] int64 , 0 , 10 )
273
- sess := db . GetEngine ( ctx ). Table ( & CommitStatus {}).
274
- Where ( "repo_id = ?" , repoID ). And ( "sha = ?" , sha ).
275
- Select ("max( id ) as id " ).
276
- GroupBy ("context_hash" ).OrderBy ("max( id ) desc" )
272
+ base := db . GetEngine ( ctx ). Table ( & CommitStatus {}).
273
+ Where ( "repo_id = ?" , repoID ). And ( "sha = ?" , sha )
274
+ indices := make ([] int64 , 0 , 10 )
275
+ sess := base . Select ("max( `index` ) as `index` " ).
276
+ GroupBy ("context_hash" ).OrderBy ("max( `index` ) desc" )
277
277
if ! listOptions .IsListAll () {
278
278
sess = db .SetSessionPagination (sess , & listOptions )
279
279
}
280
- count , err := sess .FindAndCount (& ids )
280
+ count , err := sess .FindAndCount (& indices )
281
281
if err != nil {
282
282
return nil , count , err
283
283
}
284
- statuses := make ([]* CommitStatus , 0 , len (ids ))
285
- if len (ids ) == 0 {
284
+ statuses := make ([]* CommitStatus , 0 , len (indices ))
285
+ if len (indices ) == 0 {
286
286
return statuses , count , nil
287
287
}
288
- return statuses , count , db . GetEngine ( ctx ) .In ("id " , ids ).Find (& statuses )
288
+ return statuses , count , base . And ( builder .In ("`index` " , indices ) ).Find (& statuses )
289
289
}
290
290
291
291
// GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs
0 commit comments