@@ -1247,7 +1247,7 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
1247
1247
}
1248
1248
}
1249
1249
1250
- func (opts * IssuesOptions ) setupSession (sess * xorm.Session ) {
1250
+ func (opts * IssuesOptions ) setupSessionWithLimit (sess * xorm.Session ) {
1251
1251
if opts .Page >= 0 && opts .PageSize > 0 {
1252
1252
var start int
1253
1253
if opts .Page == 0 {
@@ -1257,7 +1257,10 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
1257
1257
}
1258
1258
sess .Limit (opts .PageSize , start )
1259
1259
}
1260
+ opts .setupSessionNoLimit (sess )
1261
+ }
1260
1262
1263
+ func (opts * IssuesOptions ) setupSessionNoLimit (sess * xorm.Session ) {
1261
1264
if len (opts .IssueIDs ) > 0 {
1262
1265
sess .In ("issue.id" , opts .IssueIDs )
1263
1266
}
@@ -1423,7 +1426,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1423
1426
1424
1427
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1425
1428
1426
- opts .setupSession (sess )
1429
+ opts .setupSessionNoLimit (sess )
1427
1430
1428
1431
countsSlice := make ([]* struct {
1429
1432
RepoID int64
@@ -1433,7 +1436,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1433
1436
Select ("issue.repo_id AS repo_id, COUNT(*) AS count" ).
1434
1437
Table ("issue" ).
1435
1438
Find (& countsSlice ); err != nil {
1436
- return nil , err
1439
+ return nil , fmt . Errorf ( "unable to CountIssuesByRepo: %w" , err )
1437
1440
}
1438
1441
1439
1442
countMap := make (map [int64 ]int64 , len (countsSlice ))
@@ -1450,14 +1453,14 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
1450
1453
1451
1454
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1452
1455
1453
- opts .setupSession (sess )
1456
+ opts .setupSessionNoLimit (sess )
1454
1457
1455
1458
accessCond := accessibleRepositoryCondition (user )
1456
1459
if err := sess .Where (accessCond ).
1457
1460
Distinct ("issue.repo_id" ).
1458
1461
Table ("issue" ).
1459
1462
Find (& repoIDs ); err != nil {
1460
- return nil , err
1463
+ return nil , fmt . Errorf ( "unable to GetRepoIDsForIssuesOptions: %w" , err )
1461
1464
}
1462
1465
1463
1466
return repoIDs , nil
@@ -1468,17 +1471,16 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
1468
1471
e := db .GetEngine (db .DefaultContext )
1469
1472
1470
1473
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1471
- opts .setupSession (sess )
1474
+ opts .setupSessionWithLimit (sess )
1472
1475
sortIssuesSession (sess , opts .SortType , opts .PriorityRepoID )
1473
1476
1474
1477
issues := make ([]* Issue , 0 , opts .ListOptions .PageSize )
1475
1478
if err := sess .Find (& issues ); err != nil {
1476
- return nil , fmt .Errorf ("Find : %v " , err )
1479
+ return nil , fmt .Errorf ("unable to query Issues : %w " , err )
1477
1480
}
1478
- sess .Close ()
1479
1481
1480
1482
if err := IssueList (issues ).LoadAttributes (); err != nil {
1481
- return nil , fmt .Errorf ("LoadAttributes: %v " , err )
1483
+ return nil , fmt .Errorf ("unable to LoadAttributes for Issues : %w " , err )
1482
1484
}
1483
1485
1484
1486
return issues , nil
@@ -1489,18 +1491,17 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
1489
1491
e := db .GetEngine (db .DefaultContext )
1490
1492
1491
1493
countsSlice := make ([]* struct {
1492
- RepoID int64
1493
- Count int64
1494
+ Count int64
1494
1495
}, 0 , 1 )
1495
1496
1496
1497
sess := e .Select ("COUNT(issue.id) AS count" ).Table ("issue" )
1497
1498
sess .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1498
- opts .setupSession (sess )
1499
+ opts .setupSessionNoLimit (sess )
1499
1500
if err := sess .Find (& countsSlice ); err != nil {
1500
- return 0 , fmt .Errorf ("Find : %v " , err )
1501
+ return 0 , fmt .Errorf ("unable to CountIssues : %w " , err )
1501
1502
}
1502
- if len (countsSlice ) < 1 {
1503
- return 0 , fmt .Errorf ("there is less than one result sql record" )
1503
+ if len (countsSlice ) != 1 {
1504
+ return 0 , fmt .Errorf ("unable to get one row result when CountIssues, row count=%d" , len ( countsSlice ) )
1504
1505
}
1505
1506
return countsSlice [0 ].Count , nil
1506
1507
}
0 commit comments