@@ -1238,7 +1238,7 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
1238
1238
}
1239
1239
}
1240
1240
1241
- func (opts * IssuesOptions ) setupSession (sess * xorm.Session ) {
1241
+ func (opts * IssuesOptions ) setupSessionWithLimit (sess * xorm.Session ) {
1242
1242
if opts .Page >= 0 && opts .PageSize > 0 {
1243
1243
var start int
1244
1244
if opts .Page == 0 {
@@ -1248,7 +1248,10 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
1248
1248
}
1249
1249
sess .Limit (opts .PageSize , start )
1250
1250
}
1251
+ opts .setupSessionNoLimit (sess )
1252
+ }
1251
1253
1254
+ func (opts * IssuesOptions ) setupSessionNoLimit (sess * xorm.Session ) {
1252
1255
if len (opts .IssueIDs ) > 0 {
1253
1256
sess .In ("issue.id" , opts .IssueIDs )
1254
1257
}
@@ -1414,7 +1417,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1414
1417
1415
1418
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1416
1419
1417
- opts .setupSession (sess )
1420
+ opts .setupSessionNoLimit (sess )
1418
1421
1419
1422
countsSlice := make ([]* struct {
1420
1423
RepoID int64
@@ -1424,7 +1427,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1424
1427
Select ("issue.repo_id AS repo_id, COUNT(*) AS count" ).
1425
1428
Table ("issue" ).
1426
1429
Find (& countsSlice ); err != nil {
1427
- return nil , err
1430
+ return nil , fmt . Errorf ( "unable to CountIssuesByRepo: %w" , err )
1428
1431
}
1429
1432
1430
1433
countMap := make (map [int64 ]int64 , len (countsSlice ))
@@ -1441,14 +1444,14 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
1441
1444
1442
1445
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1443
1446
1444
- opts .setupSession (sess )
1447
+ opts .setupSessionNoLimit (sess )
1445
1448
1446
1449
accessCond := accessibleRepositoryCondition (user )
1447
1450
if err := sess .Where (accessCond ).
1448
1451
Distinct ("issue.repo_id" ).
1449
1452
Table ("issue" ).
1450
1453
Find (& repoIDs ); err != nil {
1451
- return nil , err
1454
+ return nil , fmt . Errorf ( "unable to GetRepoIDsForIssuesOptions: %w" , err )
1452
1455
}
1453
1456
1454
1457
return repoIDs , nil
@@ -1459,17 +1462,16 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
1459
1462
e := db .GetEngine (db .DefaultContext )
1460
1463
1461
1464
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1462
- opts .setupSession (sess )
1465
+ opts .setupSessionWithLimit (sess )
1463
1466
sortIssuesSession (sess , opts .SortType , opts .PriorityRepoID )
1464
1467
1465
1468
issues := make ([]* Issue , 0 , opts .ListOptions .PageSize )
1466
1469
if err := sess .Find (& issues ); err != nil {
1467
- return nil , fmt .Errorf ("Find : %v " , err )
1470
+ return nil , fmt .Errorf ("unable to query Issues : %w " , err )
1468
1471
}
1469
- sess .Close ()
1470
1472
1471
1473
if err := IssueList (issues ).LoadAttributes (); err != nil {
1472
- return nil , fmt .Errorf ("LoadAttributes: %v " , err )
1474
+ return nil , fmt .Errorf ("unable to LoadAttributes for Issues : %w " , err )
1473
1475
}
1474
1476
1475
1477
return issues , nil
@@ -1480,18 +1482,17 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
1480
1482
e := db .GetEngine (db .DefaultContext )
1481
1483
1482
1484
countsSlice := make ([]* struct {
1483
- RepoID int64
1484
- Count int64
1485
+ Count int64
1485
1486
}, 0 , 1 )
1486
1487
1487
1488
sess := e .Select ("COUNT(issue.id) AS count" ).Table ("issue" )
1488
1489
sess .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1489
- opts .setupSession (sess )
1490
+ opts .setupSessionNoLimit (sess )
1490
1491
if err := sess .Find (& countsSlice ); err != nil {
1491
- return 0 , fmt .Errorf ("Find : %v " , err )
1492
+ return 0 , fmt .Errorf ("unable to CountIssues : %w " , err )
1492
1493
}
1493
- if len (countsSlice ) < 1 {
1494
- return 0 , fmt .Errorf ("there is less than one result sql record" )
1494
+ if len (countsSlice ) != 1 {
1495
+ return 0 , fmt .Errorf ("unable to get one row result when CountIssues, row count=%d" , len ( countsSlice ) )
1495
1496
}
1496
1497
return countsSlice [0 ].Count , nil
1497
1498
}
0 commit comments