Skip to content

Commit

Permalink
fix: make sure autoPagingToArray gives all results (#3364)
Browse files Browse the repository at this point in the history
* fix: make sure autoPagingToArray gives all results

* refac: use common function to filter assets
  • Loading branch information
haakonflatval-cognite authored Jun 9, 2023
1 parent 93a1e85 commit a67fbd5
Showing 1 changed file with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
Metadata,
CogniteInternalId,
AnnotationsCogniteAnnotationTypesImagesAssetLink,
AnnotationData
AnnotationData,
AnnotationFilterProps
} from '@cognite/sdk';
import { Historical360ImageSet, Image360EventDescriptor, Image360Face, Image360FileDescriptor } from '../types';
import { Image360Provider } from '../Image360Provider';
Expand Down Expand Up @@ -77,16 +78,10 @@ export class Cdf360ImageEventProvider implements Image360Provider<Metadata> {
public async get360ImageAnnotations(descriptors: Image360FileDescriptor[]): Promise<AnnotationModel[]> {
const fileIds = descriptors.map(o => ({ id: o.fileId }));

const annotationsResult = this._client.annotations.list({
filter: {
annotatedResourceType: 'file',
annotatedResourceIds: fileIds
}
return this.listFileAnnotations({
annotatedResourceType: 'file',
annotatedResourceIds: fileIds
});

const annotationArray = await annotationsResult.autoPagingToArray();

return annotationArray;
}

public async getFilesByAssetRef(assetRef: IdEither): Promise<CogniteInternalId[]> {
Expand Down Expand Up @@ -339,15 +334,12 @@ export class Cdf360ImageEventProvider implements Image360Provider<Metadata> {
public async get360ImageAssets(image360FileDescriptors: Image360FileDescriptor[]): Promise<IdEither[]> {
const fileIds = image360FileDescriptors.map(desc => desc.fileId);
const assetListPromises = chunk(fileIds, 1000).map(async idList => {
const annotationArray = await this._client.annotations
.list({
filter: {
annotatedResourceIds: idList.map(id => ({ id })),
annotatedResourceType: 'file',
annotationType: 'images.AssetLink'
}
})
.autoPagingToArray();
const annotationArray = await this.listFileAnnotations({
annotatedResourceIds: idList.map(id => ({ id })),
annotatedResourceType: 'file',
annotationType: 'images.AssetLink'
});

const assetIds = annotationArray.map(annotation => {
assert(isAssetLinkAnnotationData(annotation.data), 'Received annotation that was not an assetLink');
return annotation.data.assetRef;
Expand All @@ -360,6 +352,15 @@ export class Cdf360ImageEventProvider implements Image360Provider<Metadata> {

return assetIds;
}

private async listFileAnnotations(filter: AnnotationFilterProps): Promise<AnnotationModel[]> {
return this._client.annotations
.list({
limit: 1000,
filter
})
.autoPagingToArray({ limit: Infinity });
}
}

function isAssetLinkAnnotationData(
Expand Down

0 comments on commit a67fbd5

Please sign in to comment.