File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed
Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ export default async function filter(
5252 const cacheKey = `${ reviewId } -${ login } ` ;
5353
5454 reqLog . debug ( `filter: checking cache key ${ cacheKey } ` ) ;
55- const curr = await getAndIncrementKV ( cacheKey ) ;
55+ const curr = await getAndIncrementKV ( cacheKey , reqLog ) ;
5656 reqLog . debug ( `filter: current value: ${ curr } ` ) ;
5757
5858 if ( curr && curr >= config . commentBurstLimit ) {
Original file line number Diff line number Diff line change 1+ import type { RequestLog } from "./util.ts" ;
2+
13const KEY_EXPIRY = 3 ; // seconds
24const MAX_RETRIES = 50 ;
35
46const kv = await Deno . openKv ( ) ;
57
6- export async function getAndIncrementKV ( key : string ) : Promise < number > {
8+ export async function getAndIncrementKV ( key : string , reqLog : RequestLog ) : Promise < number > {
79 const kvKey = [ "pr-comment" , key ] ;
810
911 // keep retrying until atomic operation succeeds with same versionstamp
@@ -17,7 +19,10 @@ export async function getAndIncrementKV(key: string): Promise<number> {
1719 . check ( res )
1820 . set ( kvKey , value + 1 , { expireIn : KEY_EXPIRY * 1000 } )
1921 . commit ( ) ;
20- if ( setRes . ok ) return value ;
22+ if ( setRes . ok ) {
23+ reqLog . debug ( `updated ${ JSON . stringify ( kvKey ) } after ${ i } retries` ) ;
24+ return value ;
25+ }
2126 }
2227
2328 throw new Error (
Original file line number Diff line number Diff line change @@ -56,3 +56,5 @@ export function requestLog(headers: Headers) {
5656 critical : proxyLog ( log . critical ) ,
5757 } ;
5858}
59+
60+ export type RequestLog = ReturnType < typeof requestLog > ;
You can’t perform that action at this time.
0 commit comments