mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-02 04:48:57 +02:00
use cache instead of async
This commit is contained in:
parent
a587c1d1da
commit
3f0fd4f771
@ -22,6 +22,8 @@ import { CipherReportComponent } from './cipher-report.component';
|
|||||||
export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit {
|
export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit {
|
||||||
passwordStrengthMap = new Map<string, [string, string]>();
|
passwordStrengthMap = new Map<string, [string, string]>();
|
||||||
|
|
||||||
|
private passwordStrengthCache = new Map<string, number>();
|
||||||
|
|
||||||
constructor(private ciphersService: CipherService, private passwordGenerationService: PasswordGenerationService,
|
constructor(private ciphersService: CipherService, private passwordGenerationService: PasswordGenerationService,
|
||||||
componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService,
|
componentFactoryResolver: ComponentFactoryResolver, messagingService: MessagingService,
|
||||||
userService: UserService) {
|
userService: UserService) {
|
||||||
@ -37,22 +39,20 @@ export class WeakPasswordsReportComponent extends CipherReportComponent implemen
|
|||||||
async setCiphers() {
|
async setCiphers() {
|
||||||
const allCiphers = await this.ciphersService.getAllDecrypted();
|
const allCiphers = await this.ciphersService.getAllDecrypted();
|
||||||
const weakPasswordCiphers: CipherView[] = [];
|
const weakPasswordCiphers: CipherView[] = [];
|
||||||
const promises: Array<Promise<any>> = [];
|
|
||||||
allCiphers.forEach((c) => {
|
allCiphers.forEach((c) => {
|
||||||
if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '') {
|
if (c.type !== CipherType.Login || c.login.password == null || c.login.password === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const promise = new Promise((resolve) => {
|
if (!this.passwordStrengthCache.has(c.login.password)) {
|
||||||
const result = this.passwordGenerationService.passwordStrength(c.login.password);
|
const result = this.passwordGenerationService.passwordStrength(c.login.password);
|
||||||
if (result.score <= 3) {
|
this.passwordStrengthCache.set(c.login.password, result.score);
|
||||||
this.passwordStrengthMap.set(c.id, this.scoreKey(result.score));
|
}
|
||||||
weakPasswordCiphers.push(c);
|
const score = this.passwordStrengthCache.get(c.login.password);
|
||||||
}
|
if (score != null && score <= 3) {
|
||||||
resolve();
|
this.passwordStrengthMap.set(c.id, this.scoreKey(score));
|
||||||
});
|
weakPasswordCiphers.push(c);
|
||||||
promises.push(promise);
|
}
|
||||||
});
|
});
|
||||||
await Promise.all(promises);
|
|
||||||
this.ciphers = weakPasswordCiphers;
|
this.ciphers = weakPasswordCiphers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user