代码之家  ›  专栏  ›  技术社区  ›  timbru31

Dexie&Angular 4:选择项目时表现缓慢

  •  2
  • timbru31  · 技术社区  · 7 年前

    表中最多只有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的区域之外运行此查询,但这并没有带来性能改进。

    1 回复  |  直到 7 年前
        1
  •  4
  •   timbru31    7 年前

    经过大量的时间和调试,我发现了以下Dexie PR,它打破了Chrome和Safari中的IndexedDB 2.0 getAll功能: https://github.com/dfahlander/Dexie.js/pull/579

    编辑 :Dexie 2.0.1已发布,并对此问题进行了正确的修复