Skip to content

Commit

Permalink
Use arrow syntax instead of bind, infinity instead of number infinity
Browse files Browse the repository at this point in the history
Fixes #5586
  • Loading branch information
jbudz committed Dec 9, 2015
1 parent 9abbd28 commit 466c695
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
Expand Up @@ -51,8 +51,8 @@ define(function (require) {
this.scanAll = function (queryString, pageSize = 1000) {
return scanner.scanAndMap(queryString, {
pageSize,
docCount: Number.POSITIVE_INFINITY
}, this.mapHits.bind(this));
docCount: Infinity
}, (hit) => this.mapHits(hit));
};

this.mapHits = function (hit) {
Expand All @@ -63,7 +63,6 @@ define(function (require) {
};

this.find = function (searchString, size = 100) {
var self = this;
var body;
if (searchString) {
body = {
Expand All @@ -85,10 +84,10 @@ define(function (require) {
body: body,
size: size
})
.then(function (resp) {
.then((resp) => {
return {
total: resp.hits.total,
hits: resp.hits.hits.map(self.mapHits.bind(self))
hits: resp.hits.hits.map((hit) => this.mapHits(hit))
};
});
};
Expand Down
Expand Up @@ -39,8 +39,8 @@ define(function (require) {
this.scanAll = function (queryString, pageSize = 1000) {
return scanner.scanAndMap(queryString, {
pageSize,
docCount: Number.POSITIVE_INFINITY
}, this.mapHits.bind(this));
docCount: Infinity
}, (hit) => this.mapHits(hit));
};


Expand All @@ -67,7 +67,6 @@ define(function (require) {
};

this.find = function (searchString, size = 100) {
var self = this;
var body;
if (searchString) {
body = {
Expand All @@ -89,10 +88,10 @@ define(function (require) {
body: body,
size: size
})
.then(function (resp) {
.then((resp) => {
return {
total: resp.hits.total,
hits: resp.hits.hits.map(self.mapHits.bind(self))
hits: resp.hits.hits.map((hit) => this.mapHits(hit))
};
});
};
Expand Down
Expand Up @@ -51,8 +51,8 @@ define(function (require) {
this.scanAll = function (queryString, pageSize = 1000) {
return scanner.scanAndMap(queryString, {
pageSize,
docCount: Number.POSITIVE_INFINITY
}, this.mapHits.bind(this));
docCount: Infinity
}, (hit) => this.mapHits(hit));
};

this.mapHits = function (hit) {
Expand All @@ -78,7 +78,6 @@ define(function (require) {
};

this.find = function (searchString, size = 100) {
var self = this;
var body;
if (searchString) {
body = {
Expand All @@ -100,10 +99,10 @@ define(function (require) {
body: body,
size: size
})
.then(function (resp) {
.then((resp) => {
return {
total: resp.hits.total,
hits: resp.hits.hits.map(self.mapHits.bind(self))
hits: resp.hits.hits.map((hit) => this.mapHits(hit))
};
});
};
Expand Down
34 changes: 18 additions & 16 deletions src/ui/public/utils/scanner.js
@@ -1,6 +1,6 @@
var _ = require('lodash');
const _ = require('lodash');

var Scanner = function (client, {index, type}) {
let Scanner = function (client, {index, type}) {
if (!index) throw new Error('Expected index');
if (!type) throw new Error('Expected type');
if (!client) throw new Error('Expected client');
Expand All @@ -16,12 +16,12 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) {
docCount: 1000
}, options);

var allResults = {
let allResults = {
hits: [],
total: 0
};

var body;
let body;
if (searchString) {
body = {
query: {
Expand All @@ -37,32 +37,34 @@ Scanner.prototype.scanAndMap = function (searchString, options, mapFn) {
}

return new Promise((resolve, reject) => {
this.client.search({
index: this.index,
type: this.type,
size: opts.pageSize,
body,
searchType: 'scan',
scroll: '1m'
}, function getMoreUntilDone(error, response) {
var scanAllResults = opts.docCount === Number.POSITIVE_INFINITY;
const getMoreUntilDone = (error, response) => {
const scanAllResults = opts.docCount === Infinity;
allResults.total = scanAllResults ? response.hits.total : Math.min(response.hits.total, opts.docCount);

var hits = response.hits.hits
let hits = response.hits.hits
.slice(0, allResults.total - allResults.hits.length);
if (mapFn) hits = hits.map(mapFn);

allResults.hits = allResults.hits.concat(hits);

var collectedAllResults = allResults.total === allResults.hits.length;
const collectedAllResults = allResults.total === allResults.hits.length;
if (collectedAllResults) {
resolve(allResults);
} else {
this.client.scroll({
scrollId: response._scroll_id,
}, getMoreUntilDone);
}
});
};

this.client.search({
index: this.index,
type: this.type,
size: opts.pageSize,
body,
searchType: 'scan',
scroll: '1m'
}, getMoreUntilDone);
});
};

Expand Down

0 comments on commit 466c695

Please sign in to comment.