在checkFilterContains时,开启root模式,以避免无限递归

This commit is contained in:
Xu Chang 2023-07-28 15:23:03 +08:00
parent 7391e141cb
commit c9844fa9c3
2 changed files with 26 additions and 4 deletions

View File

@ -5,6 +5,7 @@ var tslib_1 = require("tslib");
var assert_1 = tslib_1.__importDefault(require("assert"));
var types_1 = require("../types");
var lodash_1 = require("../utils/lodash");
var AsyncRowStore_1 = require("./AsyncRowStore");
var relation_1 = require("./relation");
function addFilterSegment() {
var filters = [];
@ -846,6 +847,7 @@ function checkFilterContains(entity, context, contained, filter, dataCompare) {
var filter2 = combineFilters([filter, {
$not: contained,
}]);
var closeRootModeFn_1 = context instanceof AsyncRowStore_1.AsyncContext && context.openRootMode();
var count = context.count(entity, {
filter: (0, lodash_1.cloneDeep)(filter2),
count: 1,
@ -854,7 +856,12 @@ function checkFilterContains(entity, context, contained, filter, dataCompare) {
blockTrigger: true,
});
if (count instanceof Promise) {
return count.then(function (count2) { return count2 === 0; });
return count.then(function (count2) {
if (closeRootModeFn_1) {
closeRootModeFn_1();
}
return count2 === 0;
});
}
return count === 0;
}
@ -873,6 +880,7 @@ function checkFilterRepel(entity, context, filter1, filter2, dataCompare) {
// 再判断两者同时成立时取得的行数是否为0
if (dataCompare) {
var filter3 = combineFilters([filter2, filter1]);
var closeRootModeFn_2 = context instanceof AsyncRowStore_1.AsyncContext && context.openRootMode();
var count = context.count(entity, {
filter: filter3,
}, {
@ -880,7 +888,10 @@ function checkFilterRepel(entity, context, filter1, filter2, dataCompare) {
blockTrigger: true,
});
if (count instanceof Promise) {
return count.then(function (count2) { return count2 === 0; });
return count.then(function (count2) {
closeRootModeFn_2 && closeRootModeFn_2();
return count2 === 0;
});
}
return count === 0;
}

View File

@ -903,6 +903,8 @@ export function checkFilterContains<ED extends EntityDict & BaseEntityDict, T ex
const filter2 = combineFilters([filter, {
$not: contained,
}]);
const closeRootModeFn = context instanceof AsyncContext && context.openRootMode();
const count = context.count(entity, {
filter: cloneDeep(filter2), // 里面的查询改写可能会把原来的filter改掉所以在此克隆
count: 1,
@ -912,7 +914,12 @@ export function checkFilterContains<ED extends EntityDict & BaseEntityDict, T ex
});
if (count instanceof Promise) {
return count.then(
(count2) => count2 === 0
(count2) => {
if (closeRootModeFn) {
closeRootModeFn();
}
return count2 === 0;
}
);
}
return count === 0;
@ -938,6 +945,7 @@ export function checkFilterRepel<ED extends EntityDict & BaseEntityDict, T exten
// 再判断两者同时成立时取得的行数是否为0
if (dataCompare) {
const filter3 = combineFilters([filter2, filter1]);
const closeRootModeFn = context instanceof AsyncContext && context.openRootMode();
const count = context.count(entity, {
filter: filter3,
}, {
@ -946,7 +954,10 @@ export function checkFilterRepel<ED extends EntityDict & BaseEntityDict, T exten
});
if (count instanceof Promise) {
return count.then(
(count2) => count2 === 0
(count2) => {
closeRootModeFn && closeRootModeFn();
return count2 === 0;
}
);
}
return count === 0;