From 4142612c7acaf921d362f46ab1e94451d1a157df Mon Sep 17 00:00:00 2001 From: Bernard Labno Date: Wed, 11 May 2016 17:51:02 +0200 Subject: [PATCH 1/2] Configurable throttling limit. --- lib/events-reader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/events-reader.js b/lib/events-reader.js index 39d22f996..0393dd1ad 100644 --- a/lib/events-reader.js +++ b/lib/events-reader.js @@ -179,7 +179,7 @@ module.exports = function (harvesterApp) { var processWithHandlerT = throttle(processWithHandler, { // call a maximum of 100 times per 1s window window: 1, - limit: 100 + limit: parseInt(_.get(harvesterApp, 'options.eventsReaderThrottleLimit'), 10) || 100 }); From 71c2f445701732e0f764daefe07c90b7c38ae6c8 Mon Sep 17 00:00:00 2001 From: Bernard Labno Date: Fri, 16 Sep 2016 07:46:23 +0200 Subject: [PATCH 2/2] Allow searching for items with empty property. --- lib/route.js | 8 ++++++-- test/app.js | 1 + test/filters.spec.js | 21 +++++++++++++++++++++ test/fixtures/people.js | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/route.js b/lib/route.js index 3ca938d92..b0220edc1 100644 --- a/lib/route.js +++ b/lib/route.js @@ -501,9 +501,13 @@ function route(harvester, name, model, schema, routeOptions) { //TODO: links.->"" is a mongodb storage issue, and should be in the mongodb adapter rather than here. //allow multiple ids or other query params at the same time. - _.each(query, function (val, key, list) { + _.each(query, function (val, key) { if (_.isString(val) && val.indexOf(',') != -1) { - query[key] = {$in: val.split(',')}; + query[key] = { + $in: val.split(',').map(function (item) { + return item.length === 0 ? null : item; + }) + }; } }); diff --git a/test/app.js b/test/app.js index 4884c9335..3e0045b16 100644 --- a/test/app.js +++ b/test/app.js @@ -11,6 +11,7 @@ var config = require('./config.js'); function configureApp(harvesterApp) { harvesterApp.resource('person', { name: Joi.string().required().description('name'), + nickname: Joi.string().description('nickname'), appearances: Joi.number().required().description('appearances'), links: { pets: ['pet'], diff --git a/test/filters.spec.js b/test/filters.spec.js index b0fdd74aa..9f6995dd0 100644 --- a/test/filters.spec.js +++ b/test/filters.spec.js @@ -1,3 +1,4 @@ +var _ = require('lodash'); var should = require('should'); var request = require('supertest'); var Promise = require('bluebird'); @@ -22,6 +23,26 @@ describe("filters", function () { done(); }); }); + it("should allow top-level resource filtering based on empty property", function (done) { + request(config.baseUrl).get('/people?nickname=,').expect('Content-Type', /json/).expect(200).end(function (error, response) { + should.not.exist(error); + var body = JSON.parse(response.text); + body.people.length.should.equal(2); + body.people.forEach(function (person) { + person.should.not.have.property('nickname'); + }); + done(); + }); + }); + it("should allow top-level resource filtering based on empty property", function (done) { + request(config.baseUrl).get('/people?nickname=Pocahontas,').expect('Content-Type', /json/).expect(200).end(function (error, response) { + should.not.exist(error); + var body = JSON.parse(response.text); + body.people.length.should.equal(3); + _.map(body.people, 'nickname').sort().should.eql(['Pocahontas', undefined, undefined]); + done(); + }); + }); it("should allow top-level resource filtering based on a numeric value", function (done) { request(config.baseUrl).get('/people?appearances=1934').expect('Content-Type', /json/).expect(200).end(function (error, response) { diff --git a/test/fixtures/people.js b/test/fixtures/people.js index 37b7f6c9e..b219a74f0 100644 --- a/test/fixtures/people.js +++ b/test/fixtures/people.js @@ -13,6 +13,7 @@ module.exports = (function () { { "id": "600274a7-3862-45d7-8fca-e558cea1cf6d", "name": "Catbert", + "nickname": "Pocahontas", "appearances": 205 } ];