Skip to content

Commit

Permalink
improve image count query performance, add a spinner when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
erinz2020 committed Dec 3, 2024
1 parent 90d18e0 commit 435328e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
28 changes: 10 additions & 18 deletions api/models/Images.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,16 @@ module.exports = {

filterByWic: async function(imageList, wicMin, wicMax) {
if (wicMin === -99999999 && wicMax === 99999999) return imageList;
let result = [];
const set = new Set();
for (const image of imageList) {
let imagesWithWic = await Annotations.find({
imageId : image.id,
});
imagesWithWic = imagesWithWic || [];
if (!imagesWithWic.length) continue;
for(const wic of imagesWithWic) {
if (wic.wicConfidence >= wicMin && wic.wicConfidence <= wicMax) {
if(!set.has(image.id)) {
result.push(image);
set.add(image.id);
}
break;
}
}
}

const imageIds = imageList.map(data => data.id);
const annotations = await Annotations.find({
imageId: { in: imageIds},
wicConfidence: { ">=": wicMin, "<=": wicMax}
});

const imageIdSet = new Set(annotations.map(annotation => annotation.imageId));
const result = imageList.filter(image => imageIdSet.has(image.id));

return result;
}

Expand Down
1 change: 1 addition & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ window.imageSelectionFormSavedInputs = {};
window.imageSelectionFormUnsavedCount = 0;
window.imageSelectionFormSavedCount = 0;
const imageSelectionFormChange = async () => {
$('#filteredImageCountModal').html('<div class="spinner-border spinner-border-sm" role="status"><span class="visually-hidden">Loading...</span></div>');
let labels = [];
const formData = new FormData(document.getElementById('imageSelectionForm'));
const formValues = {};
Expand Down

0 comments on commit 435328e

Please sign in to comment.