mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
fix(models): fix incorrect or unnecessary "scan rows" (#39516)
The six batched loaders in `IssueList` iterate their rows and never call `rows.Err()`. Refactored the code by a new helper function. --------- Signed-off-by: Calvin Tjoaquinn <calvintjoa23@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
1 parent
aa32eb97fa
commit
8c7b8d085c
10 files changed
+386
-478
No files matched your search
@@ -5,6 +5,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
@@ -198,3 +199,18 @@ func FindAndCount[T any](ctx context.Context, opts FindOptions) ([]*T, int64, er
|
||||
}
|
||||
return objects, cnt, nil
|
||||
}
|
||||
|
||||
func QueryAndProcessByChunk[IN, OUT any](in []IN, fnIn func(chunk []IN) ([]OUT, error), fnOut func(out OUT) error) error {
|
||||
for chunkIn := range slices.Chunk(in, DefaultMaxInSize) {
|
||||
chunkOut, err := fnIn(chunkIn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, out := range chunkOut {
|
||||
if err := fnOut(out); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user