@@ -221,6 +221,7 @@ func (q *Query) One(ctx context.Context, out interface{}) error {
221221 err := q .table .db .retry (ctx , func () error {
222222 var err error
223223 res , err = q .table .db .client .GetItem (ctx , req )
224+ q .cc .incRequests ()
224225 if err != nil {
225226 return err
226227 }
@@ -232,9 +233,7 @@ func (q *Query) One(ctx context.Context, out interface{}) error {
232233 if err != nil {
233234 return err
234235 }
235- if q .cc != nil {
236- addConsumedCapacity (q .cc , res .ConsumedCapacity )
237- }
236+ q .cc .add (res .ConsumedCapacity )
238237
239238 return unmarshalItem (res .Item , out )
240239 }
@@ -246,6 +245,7 @@ func (q *Query) One(ctx context.Context, out interface{}) error {
246245 err := q .table .db .retry (ctx , func () error {
247246 var err error
248247 res , err = q .table .db .client .Query (ctx , req )
248+ q .cc .incRequests ()
249249 if err != nil {
250250 return err
251251 }
@@ -264,9 +264,7 @@ func (q *Query) One(ctx context.Context, out interface{}) error {
264264 if err != nil {
265265 return err
266266 }
267- if q .cc != nil {
268- addConsumedCapacity (q .cc , res .ConsumedCapacity )
269- }
267+ q .cc .add (res .ConsumedCapacity )
270268
271269 return unmarshalItem (res .Items [0 ], out )
272270}
@@ -288,6 +286,7 @@ func (q *Query) Count(ctx context.Context) (int, error) {
288286 err := q .table .db .retry (ctx , func () error {
289287 var err error
290288 res , err = q .table .db .client .Query (ctx , input )
289+ q .cc .incRequests ()
291290 if err != nil {
292291 return err
293292 }
@@ -301,9 +300,7 @@ func (q *Query) Count(ctx context.Context) (int, error) {
301300 if err != nil {
302301 return 0 , err
303302 }
304- if q .cc != nil {
305- addConsumedCapacity (q .cc , res .ConsumedCapacity )
306- }
303+ q .cc .add (res .ConsumedCapacity )
307304
308305 q .startKey = res .LastEvaluatedKey
309306 if res .LastEvaluatedKey == nil ||
@@ -392,15 +389,14 @@ func (itr *queryIter) Next(ctx context.Context, out interface{}) bool {
392389 itr .err = itr .query .table .db .retry (ctx , func () error {
393390 var err error
394391 itr .output , err = itr .query .table .db .client .Query (ctx , itr .input )
392+ itr .query .cc .incRequests ()
395393 return err
396394 })
397395
398396 if itr .err != nil {
399397 return false
400398 }
401- if itr .query .cc != nil {
402- addConsumedCapacity (itr .query .cc , itr .output .ConsumedCapacity )
403- }
399+ itr .query .cc .add (itr .output .ConsumedCapacity )
404400 if len (itr .output .LastEvaluatedKey ) > len (itr .exLEK ) {
405401 itr .exLEK = itr .output .LastEvaluatedKey
406402 }
0 commit comments