Compare commits

...

4 Commits

Author SHA1 Message Date
e571ef347b 3.1.55 2021-02-05 21:16:46 +00:00
39a4c7ef3f fix(core): update 2021-02-05 21:16:45 +00:00
0d3518d990 3.1.54 2020-10-19 16:44:28 +00:00
fbdde2268c fix(core): update 2020-10-19 16:44:28 +00:00
5 changed files with 42 additions and 18 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartdata", "name": "@pushrocks/smartdata",
"version": "3.1.53", "version": "3.1.55",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartdata", "name": "@pushrocks/smartdata",
"version": "3.1.53", "version": "3.1.55",
"private": false, "private": false,
"description": "do more with data", "description": "do more with data",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -3,6 +3,8 @@ import { Qenv } from '@pushrocks/qenv';
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/'); const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit/');
console.log(process.memoryUsage());
// the tested module // the tested module
import * as smartdata from '../ts/index'; import * as smartdata from '../ts/index';
@ -17,6 +19,8 @@ let testDb: smartdata.SmartdataDb;
let smartdataOptions: smartdata.IMongoDescriptor; let smartdataOptions: smartdata.IMongoDescriptor;
let mongod: mongoPlugin.MongoMemoryServer; let mongod: mongoPlugin.MongoMemoryServer;
const totalCars = 2000;
tap.skip.test('should create a testinstance as database', async () => { tap.skip.test('should create a testinstance as database', async () => {
mongod = new mongoPlugin.MongoMemoryServer({}); mongod = new mongoPlugin.MongoMemoryServer({});
console.log('created mongod instance'); console.log('created mongod instance');
@ -68,7 +72,7 @@ class Car extends smartdata.SmartDataDbDoc<Car, Car> {
@smartdata.svDb() @smartdata.svDb()
deepData = { deepData = {
sodeep: 'yes' sodeep: 'yes',
}; };
constructor(colorArg: string, brandArg: string) { constructor(colorArg: string, brandArg: string) {
@ -85,46 +89,63 @@ tap.test('should save the car to the db', async () => {
const myCar2 = new Car('red', 'Volvo'); const myCar2 = new Car('red', 'Volvo');
await myCar2.save(); await myCar2.save();
let counter = 0; let counter = 0;
const totalCars = 2000; process.memoryUsage();
do { do {
const myCar3 = new Car('red', 'Renault'); const myCar3 = new Car('red', 'Renault');
await myCar3.save(); await myCar3.save();
counter++; counter++;
if (counter % 100 === 0) { if (counter % 100 === 0) {
console.log(`Filled database with ${counter} of ${totalCars} Cars`); console.log(
`Filled database with ${counter} of ${totalCars} Cars and memory usage ${
process.memoryUsage().rss / 1e6
} MB`
);
} }
} while (counter < totalCars); } while (counter < totalCars);
console.log(process.memoryUsage());
}); });
tap.test('expect to get instance of Car with shallow match', async () => { tap.test('expect to get instance of Car with shallow match', async () => {
const totalQueryCycles = totalCars / 4;
let counter = 0; let counter = 0;
do { do {
const timeStart = Date.now(); const timeStart = Date.now();
const myCars = await Car.getInstances<Car>({ const myCars = await Car.getInstances<Car>({
brand: 'Renault', brand: 'Renault',
}); });
console.log(`took ${Date.now() - timeStart}ms to query a set of 2000`); if (counter % 10 === 0) {
console.log(
`performed ${counter} of ${totalQueryCycles} total query cycles: took ${
Date.now() - timeStart
}ms to query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`
);
}
expect(myCars[0].deepData.sodeep).to.equal('yes'); expect(myCars[0].deepData.sodeep).to.equal('yes');
expect(myCars[0].brand).to.equal('Renault'); expect(myCars[0].brand).to.equal('Renault');
counter++; counter++;
} while (counter < 30); } while (counter < totalQueryCycles);
}); });
tap.test('expect to get instance of Car with deep match', async () => { tap.test('expect to get instance of Car with deep match', async () => {
const totalQueryCycles = totalCars / 4;
let counter = 0; let counter = 0;
do { do {
const timeStart = Date.now(); const timeStart = Date.now();
const myCars2 = await Car.getInstances<Car>({ const myCars2 = await Car.getInstances<Car>({
'deepData.sodeep': 'yes', 'deepData.sodeep': 'yes',
} as any); } as any);
console.log(`took ${Date.now() - timeStart}ms to query a set of 2000`); if (counter % 10 === 0) {
console.log(
`performed ${counter} of ${totalQueryCycles} total query cycles: took ${
Date.now() - timeStart
}ms to deep query a set of 2000 with memory footprint ${process.memoryUsage().rss / 1e6} MB`
);
}
expect(myCars2[0].deepData.sodeep).to.equal('yes'); expect(myCars2[0].deepData.sodeep).to.equal('yes');
expect(myCars2[0].brand).to.equal('Volvo'); expect(myCars2[0].brand).to.equal('Volvo');
counter++; counter++;
} while (counter < 30); } while (counter < totalQueryCycles);
}); });
tap.test('expect to get instance of Car and update it', async () => { tap.test('expect to get instance of Car and update it', async () => {
@ -139,7 +160,7 @@ tap.test('expect to get instance of Car and update it', async () => {
tap.test('should be able to delete an instance of car', async () => { tap.test('should be able to delete an instance of car', async () => {
const myCars = await Car.getInstances<Car>({ const myCars = await Car.getInstances<Car>({
brand: 'Volvo', brand: 'Volvo',
color: 'blue' color: 'blue',
}); });
console.log(myCars); console.log(myCars);
expect(myCars[0].color).to.equal('blue'); expect(myCars[0].color).to.equal('blue');

View File

@ -5,7 +5,10 @@ import { SmartdataDb } from './smartdata.classes.db';
export class CollectionFactory { export class CollectionFactory {
public collections: { [key: string]: SmartdataCollection<any> } = {}; public collections: { [key: string]: SmartdataCollection<any> } = {};
public getCollection = (nameArg: string, dbArg: SmartdataDb | (() => SmartdataDb)): SmartdataCollection<any> => { public getCollection = (
nameArg: string,
dbArg: SmartdataDb | (() => SmartdataDb)
): SmartdataCollection<any> => {
if (!this.collections[nameArg]) { if (!this.collections[nameArg]) {
this.collections[nameArg] = (() => { this.collections[nameArg] = (() => {
if (dbArg instanceof SmartdataDb) { if (dbArg instanceof SmartdataDb) {
@ -18,5 +21,5 @@ export class CollectionFactory {
})(); })();
} }
return this.collections[nameArg]; return this.collections[nameArg];
} };
} }

View File

@ -43,7 +43,7 @@ export class SmartdataDb {
useNewUrlParser: true, useNewUrlParser: true,
useUnifiedTopology: true, useUnifiedTopology: true,
maxPoolSize: 100, maxPoolSize: 100,
maxIdleTimeMS: 10 maxIdleTimeMS: 10,
}); });
this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName); this.mongoDb = this.mongoDbClient.db(this.smartdataOptions.mongoDbName);
this.status = 'connected'; this.status = 'connected';