优化了一下Cascade的一对多

This commit is contained in:
Xu Chang 2023-02-15 10:57:04 +08:00
parent e6bd3824d8
commit 195bf82d9f
2 changed files with 775 additions and 725 deletions

View File

@ -543,7 +543,7 @@ var CascadeStore = /** @class */ (function (_super) {
var _g = tslib_1.__read(relation, 2), entityOtm_1 = _g[0], foreignKey_2 = _g[1];
var otmOperations = data[attr];
var dealWithOneToMany = function (otm) {
var _a, _b, _c, _d, _e;
var _a, _b, _c, _d, _e, _f;
var actionOtm = otm.action, dataOtm = otm.data, filterOtm = otm.filter;
if (!foreignKey_2) {
// 基于entity/entityId的one-to-many
@ -581,13 +581,25 @@ var CascadeStore = /** @class */ (function (_super) {
}
}
else {
// 这里先假设A必是update的filter上一定有id否则用户界面上应该设计不出来这样的操作
// 这个倒是好像不可能出现create/update的一对多如果遇到了再完善
Object.assign(otm, {
filter: (0, filter_1.addFilterSegment)((_a = {},
_a[entity] = filter,
_a), filterOtm),
});
// 这里优化一下如果filter上有id直接更新成根据entityId来过滤
// 除了性能原因之外还因为会制造出user: { id: xxx }这样的查询general中不允许这样查询的出现
if (filter) {
if (filter.id && Object.keys(filter).length === 1) {
Object.assign(otm, {
filter: (0, filter_1.addFilterSegment)({
entity: entity,
entityId: filter.id,
}, filterOtm),
});
}
else {
Object.assign(otm, {
filter: (0, filter_1.addFilterSegment)((_a = {},
_a[entity] = filter,
_a), filterOtm),
});
}
}
if (action === 'remove' && actionOtm === 'update') {
Object.assign(dataOtm, {
entity: null,
@ -634,16 +646,29 @@ var CascadeStore = /** @class */ (function (_super) {
}
}
else {
// update可能出现上层filter不是根据id的userEntityGrant的过期触发的wechatQrCode的过期见general中的userEntityGrant的trigger
Object.assign(otm, {
filter: (0, filter_1.addFilterSegment)((_d = {},
_d[foreignKey_2.slice(0, foreignKey_2.length - 2)] = filter,
_d), filterOtm),
});
// 这里优化一下如果filter上有id直接更新成根据entityId来过滤
// 除了性能原因之外还因为会制造出user: { id: xxx }这样的查询general中不允许这样查询的出现
// 绝大多数情况都是id但也有可能update可能出现上层filter不是根据id的userEntityGrant的过期触发的wechatQrCode的过期见general中的userEntityGrant的trigger
if (filter) {
if (filter.id && Object.keys(filter).length === 1) {
Object.assign(otm, {
filter: (0, filter_1.addFilterSegment)((_d = {},
_d[foreignKey_2] = filter.id,
_d), filterOtm),
});
}
else {
Object.assign(otm, {
filter: (0, filter_1.addFilterSegment)((_e = {},
_e[foreignKey_2.slice(0, foreignKey_2.length - 2)] = filter,
_e), filterOtm),
});
}
}
if (action === 'remove' && actionOtm === 'update') {
Object.assign(dataOtm, (_e = {},
_e[foreignKey_2] = null,
_e));
Object.assign(dataOtm, (_f = {},
_f[foreignKey_2] = null,
_f));
}
}
}
@ -798,7 +823,7 @@ var CascadeStore = /** @class */ (function (_super) {
context,
option
);
const row = data.find(
ele => ele.id === congruentRow.id
);
@ -816,7 +841,7 @@ var CascadeStore = /** @class */ (function (_super) {
context,
option
);
return result2 + result3;
}
else {

File diff suppressed because it is too large Load Diff