Skip to content

Commit 6088f58

Browse files
fix(largefunc): restore legacy full Find results
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent c395a9e commit 6088f58

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

internal/analysis/largefunc/service.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ func New(db *gorm.DB) *Service {
4646
// @domainRule line count is computed as (end_line - start_line + 1) and must strictly exceed threshold
4747
// @see mcp.handlers.findLargeFunctions
4848
func (s *Service) Find(ctx context.Context, threshold int) ([]model.Node, error) {
49-
page, err := s.FindPage(ctx, Options{Threshold: threshold, Page: paging.Request{Limit: paging.MaxLimit}})
50-
if err != nil {
51-
return nil, err
49+
var nodes []model.Node
50+
for offset := 0; ; offset += paging.MaxLimit {
51+
page, err := s.FindPage(ctx, Options{Threshold: threshold, Page: paging.Request{Limit: paging.MaxLimit, Offset: offset}})
52+
if err != nil {
53+
return nil, err
54+
}
55+
nodes = append(nodes, page.Items...)
56+
if !page.Pagination.HasMore {
57+
return nodes, nil
58+
}
5259
}
53-
return page.Items, nil
5460
}
5561

5662
// FindPage returns a bounded page of functions and tests longer than the threshold.

internal/analysis/largefunc/service_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ func TestFind_OrderByLineCount(t *testing.T) {
137137
}
138138
}
139139

140+
func TestFind_ReturnsMoreThanMaxLimit(t *testing.T) {
141+
db := setupDB(t)
142+
for i := range make([]struct{}, paging.MaxLimit+1) {
143+
seedNode(t, db, uint(i+1), fmt.Sprintf("Func%03d", i+1), model.NodeKindFunction, 1, 100+i)
144+
}
145+
146+
svc := New(db)
147+
got, err := svc.Find(context.Background(), 30)
148+
if err != nil {
149+
t.Fatal(err)
150+
}
151+
if len(got) != paging.MaxLimit+1 {
152+
t.Fatalf("expected %d, got %d", paging.MaxLimit+1, len(got))
153+
}
154+
if got[0].Name != "Func501" || got[len(got)-1].Name != "Func001" {
155+
t.Fatalf("unexpected boundary order: first=%s last=%s", got[0].Name, got[len(got)-1].Name)
156+
}
157+
}
158+
140159
func TestFind_RespectsNamespace(t *testing.T) {
141160
db := setupDB(t)
142161
seedNodeNS(t, db, 1, "BigA", model.NodeKindFunction, 1, 100, "ns-a")

0 commit comments

Comments
 (0)