Browse Source

replaced map of singletons in backend with single singleton

pull/782/head
Stephen Hess 8 years ago
parent
commit
a4b4e286d3
  1. 2
      service/mget.js
  2. 2
      service/search.js
  3. 17
      src/backend.js
  4. 2
      test/unit/mock/backend.js

2
service/mget.js

@ -23,7 +23,7 @@ function service( backend, query, cb ){
}; };
// query new backend // 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 // log total ms elasticsearch reported the query took to execute
if( data && data.took ){ if( data && data.took ){

2
service/search.js

@ -10,7 +10,7 @@ var logger = require( 'pelias-logger' ).get( 'api' );
function service( backend, cmd, cb ){ function service( backend, cmd, cb ){
// query new backend // 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 // log total ms elasticsearch reported the query took to execute
if( data && data.took ){ if( data && data.took ){

17
src/backend.js

@ -1,14 +1,5 @@
var config = require( 'pelias-config' ).generate().esclient; const config = require( 'pelias-config' ).generate().esclient;
var Backend = require('geopipes-elasticsearch-backend'), const Backend = require('geopipes-elasticsearch-backend');
client = require('elasticsearch').Client(config), const client = require('elasticsearch').Client(config);
backends = {};
function getBackend( index, type ){ module.exports = new Backend(client);
var key = ( index + ':' + type );
if( !backends[key] ){
backends[key] = new Backend( client, index, type );
}
return backends[key];
}
module.exports = getBackend;

2
test/unit/mock/backend.js

@ -89,7 +89,7 @@ function setup( key, cmdCb ){
} }
}; };
} }
return backend; return backend();
} }
function mgetEnvelope( options ){ function mgetEnvelope( options ){

Loading…
Cancel
Save