Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter and sort on all results on Scan Results page #761

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions api/functions/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,27 +219,41 @@ exports.getAllPublicSummary = (showAll) =>
result.push(item);
}

resolve(result.filter((value, index, self) => {
return self.findIndex(v => v.runId === value.runId) === index;
}))
const seen = new Set();
const filteredResult = result.filter(value => {
if (seen.has(value.runId)) {
return false;
}
seen.add(value.runId);
return true;
})

resolve(filteredResult);
} else {
// Top 500 scans in last 24 months
// Top 500 scans in last 12 months
var date = new Date();
date.setMonth(date.getMonth() - 12);

const entity = new TableClient(azureUrl, TABLE.Scans, credential).listEntities({
queryOptions: { filter: odata`isPrivate eq ${false} and buildDate gt datetime'${date.toISOString()}'` }
});
const iterator = entity.byPage({ maxPageSize: parseInt(process.env.MAX_SCAN_SIZE) });
let result = [];
for await (const item of iterator) {
result = item;
break;
let result = []
for await (const item of entity) {
result.push(item);
}

resolve(result.filter((value, index, self) => {
return self.findIndex(v => v.runId === value.runId) === index;
}))
const seen = new Set();
const filteredResult = result.filter(value => {
if (seen.has(value.runId)) {
return false;
}
seen.add(value.runId);
return true;
})
.sort((a, b) => (a.rowKey > b.rowKey) ? 1 : -1)
.slice(0, parseInt(process.env.MAX_SCAN_SIZE));

resolve(filteredResult);
}
});

Expand Down