表中最多只有20.000个项目,但选择这些项目需要几秒钟(在Chrome 61上为5秒,在iOS 10上为20秒以上);iOS 11)
下面是我的服务,它获取两个不同的表,并通过
loadItems()
@Injectable()
export class ItemService {
private buildings: Dexie.Table<Building, string>;
private people: Dexie.Table<Person, string>;
private activeZip: string;
constructor(
private db: IndexeddbService,
) {
this.buildings = this.db.table('buildings');
this.people = this.db.table('people');
}
loadItems(): Observable<{
buildings: Building[],
people: Person[]
}> {
return Observable.combineLatest(
this.loadBuildings(),
this.loadPeople(),
).map(([buildings, people]) => {
return {
buildings,
people
};
});
}
private loadBuildings(): Observable<Building[]> {
return Observable.from(this.buildings.where('zip').equals(this.activeZip).toArray());
}
private loadPeople(): Observable<Person[]> {
return Observable.from(this.people.where('zip').equals(this.activeZip).toArray());
}
}
@Effect()
loadItems$: Observable<Action> = this.actions$
.ofType(actions.ActionTypes.LOAD_ITEMS)
.map(_ => this.itemService.setActiveZip(this.localStorageService.getActiveZip()))
.switchMap(_ => this.itemService.loadItems())
.map(items => new actions.LoadItemsSuccessAction(items))
.catch(error => Observable.of(new actions.LoadItemsFailAction(error)));
我试着通过
https://github.com/raphinesse/dexie-batch
,但最终批次需要500多秒才能到达。
哪里可能存在性能瓶颈?我已经尝试在Angular的区域之外运行此查询,但这并没有带来性能改进。