Skip to content

Commit

Permalink
fix: 🐛 post query filter assumed predicate edge metadata would always…
Browse files Browse the repository at this point in the history
… be present, fix to resume normally if not found
  • Loading branch information
marcodarko committed Jun 15, 2021
1 parent 6cb4767 commit a922134
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/batch_edge_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,36 @@ module.exports = class BatchEdgeQueryHandler {
async _postQueryFilter(response) {
try {
const filtered = response.filter(item => {
let edge_predicate = item['$edge_metadata']['predicate']
let predicate_filters = item['$edge_metadata']['trapi_qEdge_obj']['qEdge']['expanded_predicates']
//add query predicate to the expanded list
predicate_filters.concat(item['$edge_metadata']['trapi_qEdge_obj']['qEdge']['predicate'])
//remove prefix from filter list to match predicate name format
predicate_filters = predicate_filters.map((item) => utils.removeBioLinkPrefix(item));
//compare edge predicate to filter list
this.logs.push(
new LogEntry('DEBUG', null, `query_graph_handler: Current edge post-query predicate restriction includes: ${JSON.stringify(predicate_filters)}`).getLog()
);
if (predicate_filters.includes(edge_predicate)) {
debug(`ITEM ${JSON.stringify(item)}`);
if (
'predicate' in item['$edge_metadata']['trapi_qEdge_obj']['qEdge']&&
'expanded_predicates' in item['$edge_metadata']['trapi_qEdge_obj']['qEdge']
) {
let edge_predicate = item['$edge_metadata']['predicate'];
let predicate_filters = [];
predicate_filters = item['$edge_metadata']['trapi_qEdge_obj']['qEdge']['expanded_predicates'];
if (predicate_filters) {
//add query predicate to the expanded list
predicate_filters.concat(edge_predicate);
//remove prefix from filter list to match predicate name format
predicate_filters = predicate_filters.map((item) => utils.removeBioLinkPrefix(item));
//compare edge predicate to filter list
this.logs.push(
new LogEntry('DEBUG', null, `query_graph_handler: Current edge post-query predicate restriction includes: ${JSON.stringify(predicate_filters)}`).getLog()
);
if (predicate_filters.includes(edge_predicate)) {
return item;
}
}else{
// No predicate restriction on this edge, just add to results
return item
}
}else{
// No predicate restriction on this edge, just add to results
return item;
}
});
// filter result
debug(`Filtered results from ${response.length} down to ${filtered.length} results`);
this.logs.push(
new LogEntry('DEBUG', null, `query_graph_handler: Total number of results returned for this query is ${response.length}.`).getLog()
Expand All @@ -75,6 +91,7 @@ module.exports = class BatchEdgeQueryHandler {
);
return filtered
} catch (error) {
// in case of rare failure return all
debug(`Failed to filter ${response.length} results due to ${error}`);
return response;
}
Expand Down

0 comments on commit a922134

Please sign in to comment.