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

Add filter argument to ringbuffer readMany() method and a test for it API-1294 #1414

Merged
merged 2 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion src/proxy/Ringbuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,22 @@ export interface Ringbuffer<E> extends DistributedObject {
* until further items become available, and it can read at least the
* minimum number of items.
*
* filter` argument is provided to select only the items that are needed
srknzl marked this conversation as resolved.
Show resolved Hide resolved
* to be read. If the filter is not provided, all items will be read.
* Otherwise, only the items where the filter function returns true are returned.
* Using filters is a good way to prevent getting items that are of no value
* to the receiver. amount of IO and the number of operations being executed
srknzl marked this conversation as resolved.
Show resolved Hide resolved
* and can result in a significant performance improvement. Note that,
* filtering logic must be defined on the server-side.
*
* @param startSequence sequence number of the first item to be read.
* @param minCount minimum number of items to be read.
* @param maxCount maximum number of items to be read.
* @param filter optional filter to be applied to the items
srknzl marked this conversation as resolved.
Show resolved Hide resolved
* @throws RangeError if `startSequence` is smaller than `0`,
* or if `minCount` smaller than `0`,
* or if `minCount` larger than `maxCount`,
* or if `maxCount` larger than `1000` (to prevent overloading)
*/
readMany(startSequence: number | Long, minCount: number, maxCount: number): Promise<ReadResultSet<E>>;
readMany(startSequence: number | Long, minCount: number, maxCount: number, filter?: any): Promise<ReadResultSet<E>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,13 @@ describe('RingbufferProxyTest', function () {
const size = await rb.size();
expect(size.toNumber()).to.equal(2);
});

it('correctly works with prefix filter', async function () {
srknzl marked this conversation as resolved.
Show resolved Hide resolved
await rb.addAll(['item1', 'prefixedItem2', 'prefixedItem3']);
const items = await rb.readMany(0, 1, 3, new PrefixFilter('prefixed'));
expect(items.get(0)).to.equal('prefixedItem2');
expect(items.get(1)).to.equal('prefixedItem3');
expect(items.getReadCount()).to.equal(3);
expect(items.size()).to.equal(2);
});
});