Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite5ccb57

Browse files
committed
Use after_id instead of offset
1 parent202ff13 commite5ccb57

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

‎enterprise/cli/exp_aibridge.go‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math"
66
"time"
77

8+
"github.com/google/uuid"
89
"golang.org/x/xerrors"
910

1011
"github.com/coder/coder/v2/codersdk"
@@ -32,8 +33,8 @@ func (r *RootCmd) listInterceptions() *serpent.Command {
3233
startedAfterRawstring
3334
providerstring
3435
modelstring
36+
afterIDRawstring
3537
limitint64
36-
offsetint64
3738
)
3839

3940
return&serpent.Command{
@@ -70,18 +71,18 @@ func (r *RootCmd) listInterceptions() *serpent.Command {
7071
Default:"",
7172
Value:serpent.StringOf(&model),
7273
},
74+
{
75+
Flag:"after-id",
76+
Description:"The ID of the last result on the previous page to use as a pagination cursor.",
77+
Default:"",
78+
Value:serpent.StringOf(&afterIDRaw),
79+
},
7380
{
7481
Flag:"limit",
7582
Description:`The limit of results to return.`,
7683
Default:"100",
7784
Value:serpent.Int64Of(&limit),
7885
},
79-
{
80-
Flag:"offset",
81-
Description:`The offset of results to return.`,
82-
Default:"0",
83-
Value:serpent.Int64Of(&offset),
84-
},
8586
},
8687
Handler:func(inv*serpent.Invocation)error {
8788
client,err:=r.InitClient(inv)
@@ -105,6 +106,14 @@ func (r *RootCmd) listInterceptions() *serpent.Command {
105106
}
106107
}
107108

109+
afterID:=uuid.Nil
110+
ifafterIDRaw!="" {
111+
afterID,err=uuid.Parse(afterIDRaw)
112+
iferr!=nil {
113+
returnxerrors.Errorf("parse after_id filter value %q: %w",afterIDRaw,err)
114+
}
115+
}
116+
108117
iflimit>math.MaxInt32 {
109118
returnxerrors.Errorf("limit value to high")
110119
}
@@ -115,10 +124,9 @@ func (r *RootCmd) listInterceptions() *serpent.Command {
115124
exCli:=codersdk.NewExperimentalClient(client)
116125
resp,err:=exCli.AIBridgeListInterceptions(inv.Context(), codersdk.AIBridgeListInterceptionsFilter{
117126
Pagination: codersdk.Pagination{
127+
AfterID:afterID,
118128
// #nosec G115 - Safe conversion for pagination limit which is expected to be within int32 range
119129
Limit:int(limit),
120-
// #nosec G115 - Safe conversion for pagination offset which is expected to be within int32 range
121-
Offset:int(offset),
122130
},
123131
Initiator:initiator,
124132
StartedBefore:startedBefore,

‎enterprise/cli/exp_aibridge_test.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func TestAIBridgeListInterceptions(t *testing.T) {
160160
memberClient,member:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
161161

162162
now:=dbtime.Now()
163-
_=dbgen.AIBridgeInterception(t,db, database.InsertAIBridgeInterceptionParams{
163+
firstInterception:=dbgen.AIBridgeInterception(t,db, database.InsertAIBridgeInterceptionParams{
164164
InitiatorID:member.ID,
165165
StartedAt:now,
166166
})
@@ -178,7 +178,7 @@ func TestAIBridgeListInterceptions(t *testing.T) {
178178
"aibridge",
179179
"list-interceptions",
180180
"--limit","1",
181-
"--offset","1",
181+
"--after-id",firstInterception.ID.String(),
182182
}
183183
inv,root:=newCLI(t,args...)
184184
clitest.SetupConfig(t,memberClient,root)
@@ -190,7 +190,8 @@ func TestAIBridgeListInterceptions(t *testing.T) {
190190
err:=inv.WithContext(ctx).Run()
191191
require.NoError(t,err)
192192

193-
// Only contains the second interception because offset 1, limit 1.
193+
// Only contains the second interception because after_id is the first
194+
// interception, and we set a limit of 1.
194195
requireHasInterceptions(t,out.Bytes(), []uuid.UUID{returnedInterception.ID})
195196
})
196197
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp