From cb400a1ba605f5d0abb2ac2b0b56a34c9b5b0a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=9C=A8=20Audrey=20=E2=9C=A8?= Date: Mon, 1 Jul 2024 10:25:21 -0400 Subject: [PATCH] [PM-6394] remove policy evaluator cache (#9807) --- .../generator/default-generator.service.ts | 28 ++----------------- .../src/services/default-generator.service.ts | 28 ++----------------- 2 files changed, 4 insertions(+), 52 deletions(-) diff --git a/libs/common/src/tools/generator/default-generator.service.ts b/libs/common/src/tools/generator/default-generator.service.ts index cec8b75f0c..9decb309be 100644 --- a/libs/common/src/tools/generator/default-generator.service.ts +++ b/libs/common/src/tools/generator/default-generator.service.ts @@ -1,4 +1,4 @@ -import { firstValueFrom, share, timer, ReplaySubject, Observable } from "rxjs"; +import { firstValueFrom, Observable } from "rxjs"; // FIXME: use index.ts imports once policy abstractions and models // implement ADR-0002 @@ -7,13 +7,6 @@ import { UserId } from "../../types/guid"; import { GeneratorStrategy, GeneratorService, PolicyEvaluator } from "./abstractions"; -type DefaultGeneratorServiceTuning = { - /* amount of time to keep the most recent policy after a subscription ends. Once the - * cache expires, the ignoreQty and timeoutMs settings apply to the next lookup. - */ - policyCacheMs: number; -}; - /** {@link GeneratorServiceAbstraction} */ export class DefaultGeneratorService implements GeneratorService { /** Instantiates the generator service @@ -24,18 +17,8 @@ export class DefaultGeneratorService implements GeneratorServic constructor( private strategy: GeneratorStrategy, private policy: PolicyService, - tuning: Partial = {}, - ) { - this.tuning = Object.assign( - { - // a minute - policyCacheMs: 60000, - }, - tuning, - ); - } + ) {} - private tuning: DefaultGeneratorServiceTuning; private _evaluators$ = new Map>>(); /** {@link GeneratorService.options$} */ @@ -69,13 +52,6 @@ export class DefaultGeneratorService implements GeneratorServic const evaluator$ = this.policy.getAll$(this.strategy.policy, userId).pipe( // create the evaluator from the policies this.strategy.toEvaluator(), - - // cache evaluator in a replay subject to amortize creation cost - // and reduce GC pressure. - share({ - connector: () => new ReplaySubject(1), - resetOnRefCountZero: () => timer(this.tuning.policyCacheMs), - }), ); return evaluator$; diff --git a/libs/tools/generator/core/src/services/default-generator.service.ts b/libs/tools/generator/core/src/services/default-generator.service.ts index a577acd734..4fb46f5611 100644 --- a/libs/tools/generator/core/src/services/default-generator.service.ts +++ b/libs/tools/generator/core/src/services/default-generator.service.ts @@ -1,4 +1,4 @@ -import { firstValueFrom, share, timer, ReplaySubject, Observable } from "rxjs"; +import { firstValueFrom, Observable } from "rxjs"; // FIXME: use index.ts imports once policy abstractions and models // implement ADR-0002 @@ -7,13 +7,6 @@ import { UserId } from "@bitwarden/common/types/guid"; import { GeneratorStrategy, GeneratorService, PolicyEvaluator } from "../abstractions"; -type DefaultGeneratorServiceTuning = { - /* amount of time to keep the most recent policy after a subscription ends. Once the - * cache expires, the ignoreQty and timeoutMs settings apply to the next lookup. - */ - policyCacheMs: number; -}; - /** {@link GeneratorServiceAbstraction} */ export class DefaultGeneratorService implements GeneratorService { /** Instantiates the generator service @@ -24,18 +17,8 @@ export class DefaultGeneratorService implements GeneratorServic constructor( private strategy: GeneratorStrategy, private policy: PolicyService, - tuning: Partial = {}, - ) { - this.tuning = Object.assign( - { - // a minute - policyCacheMs: 60000, - }, - tuning, - ); - } + ) {} - private tuning: DefaultGeneratorServiceTuning; private _evaluators$ = new Map>>(); /** {@link GeneratorService.options$} */ @@ -69,13 +52,6 @@ export class DefaultGeneratorService implements GeneratorServic const evaluator$ = this.policy.getAll$(this.strategy.policy, userId).pipe( // create the evaluator from the policies this.strategy.toEvaluator(), - - // cache evaluator in a replay subject to amortize creation cost - // and reduce GC pressure. - share({ - connector: () => new ReplaySubject(1), - resetOnRefCountZero: () => timer(this.tuning.policyCacheMs), - }), ); return evaluator$;