diff --git a/lib/apis.js b/lib/apis.js index 6ffe6ec..057bf2c 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -78,8 +78,11 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { var modelsCache = {}; function getSiteStore(clientUrih, pkgId, dir) { - if (modelsCache[clientUrih]) { - return modelsCache[clientUrih]; + if (!modelsCache[clientUrih]) { + modelsCache[clientUrih] = apiFactories.systemSqlFactory.create({ + init: true + , dbname: clientUrih // '#' is a valid file name character + }); } // DB scopes: @@ -92,19 +95,14 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) { // scope Experience to db // scope Api by table // scope Account and Client by column - modelsCache[clientUrih] = apiFactories.systemSqlFactory.create({ - init: true - , dbname: clientUrih // '#' is a valid file name character - }).then(function (db) { + return modelsCache[clientUrih].then(function (db) { var wrap = require('masterquest-sqlite3'); return wrap.wrap(db, dir).then(function (models) { - modelsCache[clientUrih] = PromiseA.resolve(models); + //modelsCache[clientUrih] = PromiseA.resolve(models); return models; }); }); - - return modelsCache[clientUrih]; } function loadRestHelper(myConf, clientUrih, pkgId) {