优化了cascadeSelect结果,返回时剪除掉不必要的分支

This commit is contained in:
Xu Chang 2023-11-18 10:55:21 +08:00
parent d639aa9281
commit 41ed11639e
3 changed files with 15 additions and 6 deletions

View File

@ -37,8 +37,11 @@ function buildResultTree(schema, entity, result) {
else if (typeof r[attr] === 'object') {
const rel = judgeRelation(schema, e, attr);
if (rel === 2 || typeof rel === 'string') {
tree[attr] = {};
pruneInner(rel === 2 ? attr : rel, r[attr], tree[attr]);
const son = {};
pruneInner(rel === 2 ? attr : rel, r[attr], son);
if (Object.keys(son).length > 0) {
tree[attr] = son;
}
}
else if (rel instanceof Array) {
assert(r[attr] instanceof Array);

View File

@ -41,8 +41,11 @@ function buildResultTree(schema, entity, result) {
else if (typeof r[attr] === 'object') {
const rel = (0, relation_1.judgeRelation)(schema, e, attr);
if (rel === 2 || typeof rel === 'string') {
tree[attr] = {};
pruneInner(rel === 2 ? attr : rel, r[attr], tree[attr]);
const son = {};
pruneInner(rel === 2 ? attr : rel, r[attr], son);
if (Object.keys(son).length > 0) {
tree[attr] = son;
}
}
else if (rel instanceof Array) {
(0, assert_1.assert)(r[attr] instanceof Array);

View File

@ -73,8 +73,11 @@ function buildResultTree<ED extends BaseEntityDict & EntityDict, T extends keyof
else if (typeof r[attr] === 'object') {
const rel = judgeRelation(schema, e, attr);
if (rel === 2 || typeof rel === 'string') {
tree[attr] = {};
pruneInner(rel === 2 ? attr : rel, r[attr]!, tree[attr]);
const son = {}
pruneInner(rel === 2 ? attr : rel, r[attr]!, son);
if (Object.keys(son).length > 0) {
tree[attr] = son;
}
}
else if (rel instanceof Array) {
assert(r[attr] as any instanceof Array);