Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lroal committed Jul 7, 2024
1 parent 2e961ef commit 2585832
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 287 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"@typescript-eslint/eslint-plugin": "^6.x",
"@typescript-eslint/parser": "^6.x",
"@vitest/coverage-v8": "^0.34.1",
"cors": "^2.8.5",
"eslint": "^8.6.0",
"eslint": "^8.57.0",
"eslint-plugin-jest": "^27.1.7",
"express": "^4.18.2",
"msnodesqlv8": "^4.1.0",
Expand Down
293 changes: 9 additions & 284 deletions src/getManyDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function newCreateRow(span) {
const c = {};
c.visitJoin = () => { };
c.visitOne = () => { };
c.visitMany = function (leg) {
c.visitMany = function(leg) {
manyNames.push(leg.name);
};

Expand Down Expand Up @@ -58,11 +58,11 @@ function createProto(columns, span) {
}
const c = {};

c.visitJoin = function (leg) {
c.visitJoin = function(leg) {
obj[leg.name] = null;
};
c.visitOne = c.visitJoin;
c.visitMany = function (leg) {
c.visitMany = function(leg) {
obj[leg.name] = null;
};

Expand All @@ -80,7 +80,7 @@ function hasManyRelations(span) {
const c = {};
c.visitJoin = () => { };
c.visitOne = c.visitJoin;
c.visitMany = function () {
c.visitMany = function() {
result = true;
};

Expand Down Expand Up @@ -108,7 +108,7 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
const outRows = new Array(rowsLength);
const createRow = newCreateRow(span);
const shouldCreateMap = hasManyRelations(span);
let all = [];;
let all = [];

for (let i = 0; i < rowsLength; i++) {
const row = rows[i];
Expand Down Expand Up @@ -161,58 +161,6 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
if (span.legs.toArray().length === 0)
return outRows;

//alt 1
// 3.1 sec
// await new Promise((resolve, reject) => {
// setTimeout(() => {
// if (shouldCreateMap)
// decodeManyRelations(strategy, span, rows, outRows, keys)
// .then(() => decodeRelations2(strategy, span, rows, outRows, keys))
// .then(resolve)
// .catch(reject);
// else
// decodeRelations2(strategy, span, rows, outRows, keys)
// .then(resolve)
// .catch(reject);
// }, 0);
// });


//alt 1
// 3.2 sec
// await new Promise((resolve, reject) => {
// setTimeout(() => {
// const all = [];
// if (shouldCreateMap)
// all.push(decodeManyRelations(strategy, span, rows, outRows, keys))

// all.push(new Promise((resolve, reject) => {
// setTimeout(async () => {
// await decodeRelations2(strategy, span, rows, outRows, keys);
// resolve();

// }, 0);
// }));
// // const p2 = decodeRelations2(strategy, span, rows, outRows, keys);
// Promise.all(all).then(resolve, reject);
// }, 0);
// });


// let all = [];;
// if(shouldCreateMap) {

// await decodeManyRelations(strategy, span, rows, outRows, keys).then(() => decodeRelations2(strategy, span, rows, outRows, keys));
// }
// else
// await decodeRelations2(strategy, span, rows, outRows, keys);

// await Promise.all(all);



//alt 3
// 3.05 sec

if (shouldCreateMap) {
// all.push( decodeRelations2(strategy, span, rows, outRows, keys).then(() => decodeManyRelations(strategy, span)));
Expand All @@ -221,50 +169,15 @@ async function decode(strategy, span, rows, keys = rows.length > 0 ? Object.keys
// all.push( decodeManyRelations(strategy, span).then(() => decodeRelations2(strategy, span, rows, outRows, keys)));
// all.push( decodeManyRelations(strategy, span));
// all.push(decodeRelations2(strategy, span, rows, outRows, keys));
// all.push( decodeRelations2(strategy, span, rows, outRows, keys) );
// all.push( decodeRelations2(strategy, span, rows, outRows, keys) );
}
else
all.push(decodeRelations2(strategy, span, rows, outRows, keys));


await Promise.all(all);

//alt 4
// 3.02 sec
// const all = [];
// if (shouldCreateMap)
// // all.push(new Promise((resolve, reject) => {
// // setTimeout(async () => {
// // await decodeManyRelations(strategy, span);
// // resolve();

// // }, 0)
// // }));
// all.push(decodeManyRelations(strategy, span));
// all.push(new Promise((resolve, reject) => {
// setTimeout(async () => {
// await decodeRelations2(strategy, span, rows, outRows, keys);
// resolve();

// }, 0);
// }));
// await Promise.all(all);

// all.push(decodeRelations2(strategy, span, rows, outRows, keys));

//alt 4
// 3.3 sec
// if(shouldCreateMap)
// await decodeRelations(strategy, span, rows, outRows, keys);
// else
// await decodeRelations2(strategy, span, rows, outRows, keys);

// await decodeRelationsNext(strategy, span, rows, outRows, keys);
// await decodeRelations(strategy, span, rows, outRows, keys);

return outRows;


function createGetIds() {
const primaryColumns = table._primaryColumns;
const length = primaryColumns.length;
Expand All @@ -289,7 +202,7 @@ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
return;
const promises = [];
const c = {};
c.visitJoin = function (leg) {
c.visitJoin = function(leg) {
const name = leg.name;
const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
for (let i = 0; i < rows.length; i++) {
Expand Down Expand Up @@ -321,41 +234,15 @@ async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
await Promise.all(promises);
}

async function decodeRelations3(strategy, span, rawRows, resultRows, keys) {
const promises = [];
const c = {};
c.visitJoin = function (leg) {
const name = leg.name;
const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
for (let i = 0; i < rows.length; i++) {
resultRows[i][name] = rows[i];
}
});
promises.push(p);
};

c.visitOne = c.visitJoin;

c.visitMany = () => { };


span.legs.forEach(onEachLeg);

function onEachLeg(leg) {
leg.accept(c);
}

await Promise.all(promises);
}


async function decodeManyRelations(strategy, span, rawRows, resultRows, keys) {
async function decodeManyRelations(strategy, span) {
const promises = [];
const c = {};
c.visitJoin = () => { };
c.visitOne = c.visitJoin;

c.visitMany = function (leg) {
c.visitMany = function(leg) {
const name = leg.name;
const table = span.table;
const relation = table._relations[name];
Expand All @@ -371,168 +258,6 @@ async function decodeManyRelations(strategy, span, rawRows, resultRows, keys) {
promises.push(p);
};

span.legs.forEach(onEachLeg);

function onEachLeg(leg) {
leg.accept(c);
}

// await Promise.all(promises);
// }

// async function decodeRelations2(strategy, span, rawRows, resultRows, keys) {
// const promises = [];
// const c = {};
// c.visitJoin = function (leg) {
// const name = leg.name;
// //todo avoid traverse twice noMany relations below
// const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
// for (let i = 0; i < rows.length; i++) {
// resultRows[i][name] = rows[i];
// }
// });
// promises.push(p);
// };

// c.visitOne = c.visitJoin;

// c.visitMany = () => { };

// span.legs.forEach(onEachLeg);

// function onEachLeg(leg) {
// leg.accept(c);
// }

await Promise.all(promises);
}

async function decodeRelations3(strategy, span, rawRows, resultRows, keys) {

let previous = new Promise((resolve) => setImmediate(() => resolve()));
const c = {};

c.visitJoin = function (leg) {
const name = leg.name;
const p = new Promise((resolve) => {
setImmediate(() => {
decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
for (let i = 0; i < rows.length; i++) {
resultRows[i][name] = rows[i];
}
resolve();
});
});
});
previous = previous.then(() => p);
};

c.visitOne = c.visitJoin;

c.visitMany = () => { };

span.legs.forEach(onEachLeg);

function onEachLeg(leg) {
leg.accept(c);
}

await previous;

}


async function decodeRelationsNext(strategy, span, rawRows, resultRows, keys) {
// const promises = [];
let previous = new Promise((resolve) => setImmediate(() => resolve()));
const c = {};

c.visitJoin = function (leg) {
const name = leg.name;
const p = new Promise((resolve) => {
setImmediate(() => {
decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
for (let i = 0; i < rows.length; i++) {
resultRows[i][name] = rows[i];
}
resolve();
});
});
});
previous = previous.then(() => p);
};

c.visitOne = c.visitJoin;

c.visitMany = function (leg) {
const p = new Promise((resolve, reject) => {
setImmediate(() => {

const name = leg.name;
const table = span.table;
const relation = table._relations[name];
const filter = createOneFilter(relation, span._ids);
const rowsMap = span._rowsMap;

getManyDto(relation.childTable, filter, strategy[name], leg.span).then(subRows => {
for (let i = 0; i < subRows.length; i++) {
const key = leg.columns.map(column => subRows[i][column.alias]);
const parentRow = getFromMap(rowsMap, table._primaryColumns, key);
parentRow[name].push(subRows[i]);
}
}).then(() => resolve(), reject);


});
});


previous = previous.then(() => p);
// promises.push(p);
};

span.legs.forEach(onEachLeg);

function onEachLeg(leg) {
leg.accept(c);
}

await previous
}


async function decodeRelations(strategy, span, rawRows, resultRows, keys) {
const promises = [];
const c = {};
c.visitJoin = function (leg) {
const name = leg.name;
const p = decode(strategy[name], leg.span, rawRows, keys).then((rows) => {
for (let i = 0; i < rows.length; i++) {
resultRows[i][name] = rows[i];
}
});
promises.push(p);
};

c.visitOne = c.visitJoin;

c.visitMany = function (leg) {
const name = leg.name;
const table = span.table;
const relation = table._relations[name];
const filter = createOneFilter(relation, span._ids);
const rowsMap = span._rowsMap;
const p = getManyDto(relation.childTable, filter, strategy[name], leg.span).then(subRows => {
for (let i = 0; i < subRows.length; i++) {
const key = leg.columns.map(column => subRows[i][column.alias]);
const parentRow = getFromMap(rowsMap, table._primaryColumns, key);
parentRow[name].push(subRows[i]);
}
});
promises.push(p);
};


span.legs.forEach(onEachLeg);

function onEachLeg(leg) {
Expand Down

0 comments on commit 2585832

Please sign in to comment.