2017-09-28 56 views
0

我在使用Angular 4應用程序中的Dexie從我的IndexedDB查詢中選擇項目(在1.000和4.000之間)時遇到問題。Dexie&Angular 4:選擇項目時性能下降

只有表中最高20.000項目,但這些選擇需要多秒(5S在Chrome 61,高達(及以上)比20多歲的iOS上的10 & 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()); 
    } 
} 

取兩個不同的表,並返回可觀察到的所得的可觀察是異步與NGRX效果,這將調度該數據寫入的狀態的動作處理,因此該組件可以呈現的信息。

@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塊中的項目,但由此產生的批花500ms以上才能到達。

哪裏有可能的性能瓶頸?我已經嘗試在Angular的區域之外運行這個查詢,但是這並沒有提高性能和性能。

+0

你想在頁面上同時放置4000個項目? – alexKhymenko

+0

創建一個plunker – Aravind

+0

@alexKhymenko - 不,信息在商店中,並通過滾動指令,我只在用戶觸及底部時向視圖添加50個項目。試圖在用戶觸及底部時直接從數據庫中加載項目,但即使iPad在這方面速度太慢。 – timbru31

回答

0

隨着大量的時間和調試,我已經確定了以下Dexie PR打破了IndexedDB的2.0 GETALL功能在Chrome和Safari:https://github.com/dfahlander/Dexie.js/pull/579

隨着恢復到Dexie 2.0.0 beta.11性能(通過光標原始數據庫查詢GETALL從600-700ms回到60ms的)10倍左右的時間增加

編輯:Dexie 2.0.1已經發布了正確的修復此問題