var model = null;

module.exports = function modelLoader(isParent) {
    'use strict';

    if (isParent || process.env.MCTEST) {
        return require('./mocks/model');
    }

    if (!model) {
        let ropts = {
            db: process.env.MCDB || 'materialscommons',
            port: process.env.MCPORT || 30815
        };

        let r = require('rethinkdbdash')(ropts);
        model = require('./db/model')(r);
    }

    return model;
};

var model = null;

module.exports = function modelLoader(isParent) {
    'use strict';

    if (model) {
        return model;
    }

    if (isParent || process.env.MCTEST) {
        model = require('./mocks/model');
    } else {
        let ropts = {
            db: process.env.MCDB || 'materialscommons',
            port: process.env.MCPORT || 30815
        };

        let r = require('rethinkdbdash')(ropts);
        model = require('./db/model')(r);
    }

    return model;
};

Change model-loader so it only creates the model once.