From 3f0fd4f7710696ef017586b57f247602a7578868 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 12 Dec 2018 11:22:11 -0500 Subject: [PATCH] use cache instead of async --- .../tools/weak-passwords-report.component.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/tools/weak-passwords-report.component.ts b/src/app/tools/weak-passwords-report.component.ts index eb5e99b08f..ae19d30407 100644 --- a/src/app/tools/weak-passwords-report.component.ts +++ b/src/app/tools/weak-passwords-report.component.ts @@ -22,6 +22,8 @@ import { CipherReportComponent } from './cipher-report.component'; export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit { passwordStrengthMap = new Map(); + private passwordStrengthCache = new Map(); + constructor(private ciphersService: CipherService, private passwordGenerationService: PasswordGenerationService, componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService, userService: UserService) { @@ -37,22 +39,20 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen async setCiphers() { const allCiphers = await this.ciphersService.getAllDecrypted(); const weakPasswordCiphers: CipherView[] = []; - const promises: Array> = []; allCiphers.forEach((c) => { if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '') { return; } - const promise = new Promise((resolve) => { + if (!this.passwordStrengthCache.has(c.login.password)) { const result = this.passwordGenerationService.passwordStrength(c.login.password); - if (result.score <= 3) { - this.passwordStrengthMap.set(c.id, this.scoreKey(result.score)); - weakPasswordCiphers.push(c); - } - resolve(); - }); - promises.push(promise); + this.passwordStrengthCache.set(c.login.password, result.score); + } + const score = this.passwordStrengthCache.get(c.login.password); + if (score != null && score <= 3) { + this.passwordStrengthMap.set(c.id, this.scoreKey(score)); + weakPasswordCiphers.push(c); + } }); - await Promise.all(promises); this.ciphers = weakPasswordCiphers; }