popup search service to avoid background page marshalling

This commit is contained in:
Kyle Spearrin 2018-08-16 23:33:07 -04:00
parent 08aadcb032
commit d56dfab2fe
4 changed files with 34 additions and 5 deletions

2
jslib

@ -1 +1 @@
Subproject commit f16fc58d707b9ed55355e62440fb95185f972090
Subproject commit 9ba3c176262b7d06209998305ab73d91c3e72458

View File

@ -0,0 +1,23 @@
import { CipherService } from 'jslib/abstractions/cipher.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { SearchService } from 'jslib/services/search.service';
export class PopupSearchService extends SearchService {
constructor(private mainSearchService: SearchService, cipherService: CipherService,
platformUtilsService: PlatformUtilsService) {
super(cipherService, platformUtilsService);
}
clearIndex() {
throw new Error('Not available.');
}
indexCiphers(): Promise<void> {
throw new Error('Not available.');
}
getIndexForSearch() {
return this.mainSearchService.getIndexForSearch();
}
}

View File

@ -29,7 +29,7 @@ import { LockService } from 'jslib/abstractions/lock.service';
import { MessagingService } from 'jslib/abstractions/messaging.service';
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { SearchService } from 'jslib/abstractions/search.service';
import { SearchService as SearchServiceAbstraction } from 'jslib/abstractions/search.service';
import { SettingsService } from 'jslib/abstractions/settings.service';
import { StateService as StateServiceAbstraction } from 'jslib/abstractions/state.service';
import { StorageService } from 'jslib/abstractions/storage.service';
@ -43,10 +43,12 @@ import BrowserMessagingService from '../../services/browserMessaging.service';
import { AuthService } from 'jslib/services/auth.service';
import { ConstantsService } from 'jslib/services/constants.service';
import { SearchService } from 'jslib/services/search.service';
import { StateService } from 'jslib/services/state.service';
import { Analytics } from 'jslib/misc/analytics';
import { PopupSearchService } from './popup-search.service';
import { PopupUtilsService } from './popup-utils.service';
function getBgService<T>(service: string) {
@ -63,6 +65,8 @@ export const authService = new AuthService(getBgService<CryptoService>('cryptoSe
getBgService<TokenService>('tokenService')(), getBgService<AppIdService>('appIdService')(),
getBgService<I18nService>('i18nService')(), getBgService<PlatformUtilsService>('platformUtilsService')(),
messagingService);
export const searchService = new PopupSearchService(getBgService<SearchService>('searchService')(),
getBgService<CipherService>('cipherService')(), getBgService<PlatformUtilsService>('platformUtilsService')());
export function initFactory(i18nService: I18nService, storageService: StorageService,
popupUtilsService: PopupUtilsService): Function {
@ -113,6 +117,7 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer
{ provide: MessagingService, useValue: messagingService },
{ provide: AuthServiceAbstraction, useValue: authService },
{ provide: StateServiceAbstraction, useValue: stateService },
{ provide: SearchServiceAbstraction, useValue: searchService },
{ provide: AuditService, useFactory: getBgService<AuditService>('auditService'), deps: [] },
{ provide: CipherService, useFactory: getBgService<CipherService>('cipherService'), deps: [] },
{ provide: FolderService, useFactory: getBgService<FolderService>('folderService'), deps: [] },
@ -141,7 +146,6 @@ export function initFactory(i18nService: I18nService, storageService: StorageSer
{ provide: AppIdService, useFactory: getBgService<AppIdService>('appIdService'), deps: [] },
{ provide: AutofillService, useFactory: getBgService<AutofillService>('autofillService'), deps: [] },
{ provide: ExportService, useFactory: getBgService<ExportService>('exportService'), deps: [] },
{ provide: SearchService, useFactory: getBgService<SearchService>('searchService'), deps: [] },
{
provide: APP_INITIALIZER,
useFactory: initFactory,

View File

@ -62,6 +62,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
private searchTimeout: any = null;
private hasSearched = false;
private hasLoadedAllCiphers = false;
private allCiphers: CipherView[] = null;
constructor(collectionService: CollectionService, folderService: FolderService,
private cipherService: CipherService, private router: Router,
@ -154,6 +155,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
}
async loadCiphers() {
this.allCiphers = await this.cipherService.getAllDecrypted();
if (!this.hasLoadedAllCiphers) {
this.hasLoadedAllCiphers = !this.searchService.isSearchable(this.searchText);
}
@ -216,7 +218,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
}
if (timeout == null) {
this.hasSearched = this.searchService.isSearchable(this.searchText);
this.ciphers = await this.searchService.searchCiphers(this.searchText, null);
this.ciphers = await this.searchService.searchCiphers(this.searchText, null, this.allCiphers);
return;
}
this.searchPending = true;
@ -225,7 +227,7 @@ export class GroupingsComponent extends BaseGroupingsComponent implements OnInit
if (!this.hasLoadedAllCiphers && !this.hasSearched) {
await this.loadCiphers();
} else {
this.ciphers = await this.searchService.searchCiphers(this.searchText, null);
this.ciphers = await this.searchService.searchCiphers(this.searchText, null, this.allCiphers);
}
this.searchPending = false;
}, timeout);