Skip to content

Commit

Permalink
feat(restquery): allow queries with more than 1000 msgs as result
Browse files Browse the repository at this point in the history
A filter can now contain the "maxNrMsgs" key.
It can either be a positive number or 0 for all.
If a pos. number is provided the maximum of 1000 and all provided numbers is used.
If 0 is used the max is set to unlimited.
This should be used with caution and only in cases where e.g. the result of
all msgs is needed and processed afterwards e.g. with a javascript function.
  • Loading branch information
mbehr1 committed Jan 17, 2021
1 parent 9f5d528 commit 56872cc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/dltDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1880,15 +1880,22 @@ export class DltDocument {
const queryFilters = JSON.parse(commandParams);
console.log(`filters=`, queryFilters);
if (Array.isArray(queryFilters) && queryFilters.length > 0) {
let maxNrMsgs = 1000; // default to 1000 msgs to report as result
const filters: DltFilter[] = [];
for (let i = 0; i < queryFilters.length; ++i) {
const filterAttribs = queryFilters[i];
if ('maxNrMsgs' in filterAttribs) {
const fMaxNrMsgs = filterAttribs['maxNrMsgs'];
if (fMaxNrMsgs === 0) { maxNrMsgs = this.msgs.length; } else
if (fMaxNrMsgs > maxNrMsgs) { maxNrMsgs = fMaxNrMsgs; }
delete filterAttribs['maxNrMsgs'];
}
const filter = new DltFilter(filterAttribs, false);
filters.push(filter);
}
// now get the matching message:
if (filters.length > 0) {
const matches = DltDocument.getMatchingMessages(this.msgs, filters, 1000); // max 1000 messages for now
const matches = DltDocument.getMatchingMessages(this.msgs, filters, maxNrMsgs);
retObj.data = util.createRestArray(matches, (obj: object, i: number) => { const msg = obj as DltMsg; return msg.asRestObject(i); });
} else {
if (!Array.isArray(retObj.error)) { retObj.error = []; }
Expand Down

0 comments on commit 56872cc

Please sign in to comment.