Browse Source

Alias: Batch support for fetching entities from relations

pull/2888/head
Igor Kulikov 6 years ago
parent
commit
fe36f91890
  1. 30
      ui-ngx/src/app/core/http/entity.service.ts

30
ui-ngx/src/app/core/http/entity.service.ts

@ -1007,16 +1007,40 @@ export class EntityService {
private entityRelationInfosToEntitiesInfo(entityRelations: Array<EntityRelationInfo>,
direction: EntitySearchDirection): Observable<Array<EntityInfo>> {
if (entityRelations.length) {
const tasks: Observable<EntityInfo>[] = [];
const packs: Observable<EntityInfo>[][] = [];
let packTasks: Observable<EntityInfo>[] = [];
entityRelations.forEach((entityRelation) => {
tasks.push(this.entityRelationInfoToEntityInfo(entityRelation, direction));
packTasks.push(this.entityRelationInfoToEntityInfo(entityRelation, direction));
if (packTasks.length === 100) {
packs.push(packTasks);
packTasks = [];
}
});
return forkJoin(tasks);
if (packTasks.length) {
packs.push(packTasks);
}
return this.executePack(packs, 0);
} else {
return of([]);
}
}
private executePack(packs: Observable<EntityInfo>[][], index: number): Observable<Array<EntityInfo>> {
return forkJoin(packs[index]).pipe(
expand(() => {
index++;
if (packs[index]) {
return forkJoin(packs[index]);
} else {
return EMPTY;
}
}
),
concatMap((data) => data),
toArray()
);
}
private entityRelationInfoToEntityInfo(entityRelationInfo: EntityRelationInfo, direction: EntitySearchDirection): Observable<EntityInfo> {
const entityId = direction === EntitySearchDirection.FROM ? entityRelationInfo.to : entityRelationInfo.from;
return this.getEntity(entityId.entityType as EntityType, entityId.id, {ignoreLoading: true, ignoreErrors: true}).pipe(

Loading…
Cancel
Save