Skip to content

Commit

Permalink
performance improvement for choosing representative taxon photos
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Dec 19, 2024
1 parent a3cb5ee commit f319554
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/controllers/v1/computervision_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,27 @@ const ComputervisionController = class ComputervisionController {
hit.ancestor_ids = _.remove( hit.ancestor_ids, ancestorID => ancestorID === hit.id );
hit.ancestor_ids.push( hit.taxon_id );
} );
await ObservationPreload.assignObservationPhotoPhotos( embeddingsHits );
const representativeTaxonPhotos = [];
_.each( results, result => {
if ( result && result.taxon && result.taxon.default_photo ) {
const firstMatch = _.find( embeddingsHits, h => (
h?.photo?.url
&& _.includes( h.ancestor_ids, result.taxon.id )
h?.photo_id && _.includes( h.ancestor_ids, result.taxon.id )
) );
if ( firstMatch ) {
result.taxon.default_photo.url = firstMatch.photo.url.replace( "medium", "square" );
result.taxon.default_photo.medium_url = firstMatch.photo.url;
result.taxon.default_photo.square_url = firstMatch.photo.url.replace( "medium", "square" );
if ( !firstMatch ) {
return;
}
representativeTaxonPhotos.push( {
taxon: result.taxon,
photo_id: firstMatch.photo_id
} );
}
} );
await ObservationPreload.assignObservationPhotoPhotos( representativeTaxonPhotos );
_.each( representativeTaxonPhotos, taxonPhoto => {
if ( taxonPhoto?.photo?.url ) {
taxonPhoto.taxon.default_photo.url = taxonPhoto.photo.url.replace( "medium", "square" );
taxonPhoto.taxon.default_photo.medium_url = taxonPhoto.photo.url;
taxonPhoto.taxon.default_photo.square_url = taxonPhoto.photo.url.replace( "medium", "square" );
}
} );
}
Expand Down

0 comments on commit f319554

Please sign in to comment.