@@ -1270,7 +1270,7 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
1270
1270
}
1271
1271
}
1272
1272
1273
- func (opts * IssuesOptions ) setupSession (sess * xorm.Session ) {
1273
+ func (opts * IssuesOptions ) setupSessionWithLimit (sess * xorm.Session ) {
1274
1274
if opts .Page >= 0 && opts .PageSize > 0 {
1275
1275
var start int
1276
1276
if opts .Page == 0 {
@@ -1280,7 +1280,10 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
1280
1280
}
1281
1281
sess .Limit (opts .PageSize , start )
1282
1282
}
1283
+ opts .setupSessionNoLimit (sess )
1284
+ }
1283
1285
1286
+ func (opts * IssuesOptions ) setupSessionNoLimit (sess * xorm.Session ) {
1284
1287
if len (opts .IssueIDs ) > 0 {
1285
1288
sess .In ("issue.id" , opts .IssueIDs )
1286
1289
}
@@ -1446,7 +1449,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1446
1449
1447
1450
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1448
1451
1449
- opts .setupSession (sess )
1452
+ opts .setupSessionNoLimit (sess )
1450
1453
1451
1454
countsSlice := make ([]* struct {
1452
1455
RepoID int64
@@ -1456,7 +1459,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
1456
1459
Select ("issue.repo_id AS repo_id, COUNT(*) AS count" ).
1457
1460
Table ("issue" ).
1458
1461
Find (& countsSlice ); err != nil {
1459
- return nil , err
1462
+ return nil , fmt . Errorf ( "unable to CountIssuesByRepo: %w" , err )
1460
1463
}
1461
1464
1462
1465
countMap := make (map [int64 ]int64 , len (countsSlice ))
@@ -1473,14 +1476,14 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
1473
1476
1474
1477
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1475
1478
1476
- opts .setupSession (sess )
1479
+ opts .setupSessionNoLimit (sess )
1477
1480
1478
1481
accessCond := accessibleRepositoryCondition (user )
1479
1482
if err := sess .Where (accessCond ).
1480
1483
Distinct ("issue.repo_id" ).
1481
1484
Table ("issue" ).
1482
1485
Find (& repoIDs ); err != nil {
1483
- return nil , err
1486
+ return nil , fmt . Errorf ( "unable to GetRepoIDsForIssuesOptions: %w" , err )
1484
1487
}
1485
1488
1486
1489
return repoIDs , nil
@@ -1491,17 +1494,16 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
1491
1494
e := db .GetEngine (db .DefaultContext )
1492
1495
1493
1496
sess := e .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1494
- opts .setupSession (sess )
1497
+ opts .setupSessionWithLimit (sess )
1495
1498
sortIssuesSession (sess , opts .SortType , opts .PriorityRepoID )
1496
1499
1497
1500
issues := make ([]* Issue , 0 , opts .ListOptions .PageSize )
1498
1501
if err := sess .Find (& issues ); err != nil {
1499
- return nil , fmt .Errorf ("Find : %v " , err )
1502
+ return nil , fmt .Errorf ("unable to query Issues : %w " , err )
1500
1503
}
1501
- sess .Close ()
1502
1504
1503
1505
if err := IssueList (issues ).LoadAttributes (); err != nil {
1504
- return nil , fmt .Errorf ("LoadAttributes: %v " , err )
1506
+ return nil , fmt .Errorf ("unable to LoadAttributes for Issues : %w " , err )
1505
1507
}
1506
1508
1507
1509
return issues , nil
@@ -1512,18 +1514,17 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
1512
1514
e := db .GetEngine (db .DefaultContext )
1513
1515
1514
1516
countsSlice := make ([]* struct {
1515
- RepoID int64
1516
- Count int64
1517
+ Count int64
1517
1518
}, 0 , 1 )
1518
1519
1519
1520
sess := e .Select ("COUNT(issue.id) AS count" ).Table ("issue" )
1520
1521
sess .Join ("INNER" , "repository" , "`issue`.repo_id = `repository`.id" )
1521
- opts .setupSession (sess )
1522
+ opts .setupSessionNoLimit (sess )
1522
1523
if err := sess .Find (& countsSlice ); err != nil {
1523
- return 0 , fmt .Errorf ("Find : %v " , err )
1524
+ return 0 , fmt .Errorf ("unable to CountIssues : %w " , err )
1524
1525
}
1525
- if len (countsSlice ) < 1 {
1526
- return 0 , fmt .Errorf ("there is less than one result sql record" )
1526
+ if len (countsSlice ) != 1 {
1527
+ return 0 , fmt .Errorf ("unable to get one row result when CountIssues, row count=%d" , len ( countsSlice ) )
1527
1528
}
1528
1529
return countsSlice [0 ].Count , nil
1529
1530
}
0 commit comments