@@ -10,14 +10,7 @@ import { glob } from "glob";
1010import { load } from "js-yaml" ;
1111import { join , basename , dirname } from "path" ;
1212import { dirSync } from "tmp-promise" ;
13- import {
14- ExtensionContext ,
15- Uri ,
16- window as Window ,
17- workspace ,
18- env ,
19- WorkspaceFolder ,
20- } from "vscode" ;
13+ import { Uri , window as Window , workspace , env , WorkspaceFolder } from "vscode" ;
2114import { CodeQLCliServer , QlpacksInfo } from "./codeql-cli/cli" ;
2215import { UserCancellationException } from "./common/vscode/progress" ;
2316import { extLogger , OutputChannelLogger } from "./common" ;
@@ -363,106 +356,6 @@ export async function prepareCodeTour(
363356 }
364357}
365358
366- /**
367- * Provides a utility method to invoke a function only if a minimum time interval has elapsed since
368- * the last invocation of that function.
369- */
370- export class InvocationRateLimiter < T > {
371- constructor (
372- extensionContext : ExtensionContext ,
373- funcIdentifier : string ,
374- func : ( ) => Promise < T > ,
375- createDate : ( dateString ?: string ) => Date = ( s ) =>
376- s ? new Date ( s ) : new Date ( ) ,
377- ) {
378- this . _createDate = createDate ;
379- this . _extensionContext = extensionContext ;
380- this . _func = func ;
381- this . _funcIdentifier = funcIdentifier ;
382- }
383-
384- /**
385- * Invoke the function if `minSecondsSinceLastInvocation` seconds have elapsed since the last invocation.
386- */
387- public async invokeFunctionIfIntervalElapsed (
388- minSecondsSinceLastInvocation : number ,
389- ) : Promise < InvocationRateLimiterResult < T > > {
390- const updateCheckStartDate = this . _createDate ( ) ;
391- const lastInvocationDate = this . getLastInvocationDate ( ) ;
392- if (
393- minSecondsSinceLastInvocation &&
394- lastInvocationDate &&
395- lastInvocationDate <= updateCheckStartDate &&
396- lastInvocationDate . getTime ( ) + minSecondsSinceLastInvocation * 1000 >
397- updateCheckStartDate . getTime ( )
398- ) {
399- return createRateLimitedResult ( ) ;
400- }
401- const result = await this . _func ( ) ;
402- await this . setLastInvocationDate ( updateCheckStartDate ) ;
403- return createInvokedResult ( result ) ;
404- }
405-
406- private getLastInvocationDate ( ) : Date | undefined {
407- const maybeDateString : string | undefined =
408- this . _extensionContext . globalState . get (
409- InvocationRateLimiter . _invocationRateLimiterPrefix +
410- this . _funcIdentifier ,
411- ) ;
412- return maybeDateString ? this . _createDate ( maybeDateString ) : undefined ;
413- }
414-
415- private async setLastInvocationDate ( date : Date ) : Promise < void > {
416- return await this . _extensionContext . globalState . update (
417- InvocationRateLimiter . _invocationRateLimiterPrefix + this . _funcIdentifier ,
418- date ,
419- ) ;
420- }
421-
422- private readonly _createDate : ( dateString ?: string ) => Date ;
423- private readonly _extensionContext : ExtensionContext ;
424- private readonly _func : ( ) => Promise < T > ;
425- private readonly _funcIdentifier : string ;
426-
427- private static readonly _invocationRateLimiterPrefix =
428- "invocationRateLimiter_lastInvocationDate_" ;
429- }
430-
431- export enum InvocationRateLimiterResultKind {
432- Invoked ,
433- RateLimited ,
434- }
435-
436- /**
437- * The function was invoked and returned the value `result`.
438- */
439- interface InvokedResult < T > {
440- kind : InvocationRateLimiterResultKind . Invoked ;
441- result : T ;
442- }
443-
444- /**
445- * The function was not invoked as the minimum interval since the last invocation had not elapsed.
446- */
447- interface RateLimitedResult {
448- kind : InvocationRateLimiterResultKind . RateLimited ;
449- }
450-
451- type InvocationRateLimiterResult < T > = InvokedResult < T > | RateLimitedResult ;
452-
453- function createInvokedResult < T > ( result : T ) : InvokedResult < T > {
454- return {
455- kind : InvocationRateLimiterResultKind . Invoked ,
456- result,
457- } ;
458- }
459-
460- function createRateLimitedResult ( ) : RateLimitedResult {
461- return {
462- kind : InvocationRateLimiterResultKind . RateLimited ,
463- } ;
464- }
465-
466359export interface QlPacksForLanguage {
467360 /** The name of the pack containing the dbscheme. */
468361 dbschemePack : string ;
0 commit comments