From a4b4e286d30e7cb1903ec8d14cae34b9595bbb8c Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Mon, 9 Jan 2017 22:56:51 -0500 Subject: [PATCH] replaced map of singletons in backend with single singleton --- service/mget.js | 2 +- service/search.js | 2 +- src/backend.js | 17 ++++------------- test/unit/mock/backend.js | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/service/mget.js b/service/mget.js index c709f28e..681582e3 100644 --- a/service/mget.js +++ b/service/mget.js @@ -23,7 +23,7 @@ function service( backend, query, cb ){ }; // query new backend - backend().client.mget( cmd, function( err, data ){ + backend.client.mget( cmd, function( err, data ){ // log total ms elasticsearch reported the query took to execute if( data && data.took ){ diff --git a/service/search.js b/service/search.js index 8e12b69e..1776fb8c 100644 --- a/service/search.js +++ b/service/search.js @@ -10,7 +10,7 @@ var logger = require( 'pelias-logger' ).get( 'api' ); function service( backend, cmd, cb ){ // query new backend - backend().client.search( cmd, function( err, data ){ + backend.client.search( cmd, function( err, data ){ // log total ms elasticsearch reported the query took to execute if( data && data.took ){ diff --git a/src/backend.js b/src/backend.js index c983dbba..e99ca5d2 100644 --- a/src/backend.js +++ b/src/backend.js @@ -1,14 +1,5 @@ -var config = require( 'pelias-config' ).generate().esclient; -var Backend = require('geopipes-elasticsearch-backend'), - client = require('elasticsearch').Client(config), - backends = {}; +const config = require( 'pelias-config' ).generate().esclient; +const Backend = require('geopipes-elasticsearch-backend'); +const client = require('elasticsearch').Client(config); -function getBackend( index, type ){ - var key = ( index + ':' + type ); - if( !backends[key] ){ - backends[key] = new Backend( client, index, type ); - } - return backends[key]; -} - -module.exports = getBackend; +module.exports = new Backend(client); diff --git a/test/unit/mock/backend.js b/test/unit/mock/backend.js index 739ed2cb..9292fe33 100644 --- a/test/unit/mock/backend.js +++ b/test/unit/mock/backend.js @@ -89,7 +89,7 @@ function setup( key, cmdCb ){ } }; } - return backend; + return backend(); } function mgetEnvelope( options ){