加强了filterRepel的判定
This commit is contained in:
parent
7741fca86b
commit
87d8ea3761
|
|
@ -31,12 +31,12 @@ exports.desc = {
|
||||||
name: 'index_entity_relation',
|
name: 'index_entity_relation',
|
||||||
attributes: [
|
attributes: [
|
||||||
{
|
{
|
||||||
name: 'destEntity'
|
name: 'destEntity',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relationId"
|
name: "relationId",
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -45,15 +45,15 @@ exports.desc = {
|
||||||
name: 'namespace_language',
|
name: 'namespace_language',
|
||||||
attributes: [
|
attributes: [
|
||||||
{
|
{
|
||||||
name: 'namespace'
|
name: 'namespace',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'language'
|
name: 'language',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
config: {
|
config: {
|
||||||
unique: true
|
unique: true,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ exports.ActionDefDict = exports.actions = void 0;
|
||||||
const IActionDef = {
|
const IActionDef = {
|
||||||
stm: {
|
stm: {
|
||||||
apply: ['active', 'applied'],
|
apply: ['active', 'applied'],
|
||||||
abandon: ['active', 'abandoned']
|
abandon: ['active', 'abandoned'],
|
||||||
},
|
},
|
||||||
is: 'active'
|
is: 'active',
|
||||||
};
|
};
|
||||||
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "apply", "abandon"];
|
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "apply", "abandon"];
|
||||||
exports.ActionDefDict = {
|
exports.ActionDefDict = {
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,9 @@ exports.desc = {
|
||||||
attributes: [
|
attributes: [
|
||||||
{
|
{
|
||||||
name: 'iState',
|
name: 'iState',
|
||||||
direction: 'ASC'
|
direction: 'ASC',
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -37,18 +37,18 @@ exports.desc = {
|
||||||
name: 'index_targetEntity_entityId_name',
|
name: 'index_targetEntity_entityId_name',
|
||||||
attributes: [
|
attributes: [
|
||||||
{
|
{
|
||||||
name: 'entity'
|
name: 'entity',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'entityId'
|
name: 'entityId',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'name'
|
name: 'name',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
config: {
|
config: {
|
||||||
unique: true
|
unique: true,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -29,18 +29,18 @@ exports.desc = {
|
||||||
name: 'index_entity_relation_path',
|
name: 'index_entity_relation_path',
|
||||||
attributes: [
|
attributes: [
|
||||||
{
|
{
|
||||||
name: "sourceRelationId"
|
name: "sourceRelationId",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'path'
|
name: 'path',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "destRelationId"
|
name: "destRelationId",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
config: {
|
config: {
|
||||||
unique: true
|
unique: true,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ exports.ActionDefDict = exports.actions = void 0;
|
||||||
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "grant", "revoke", "mergeTo"];
|
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "grant", "revoke", "mergeTo"];
|
||||||
const UserActionDef = {
|
const UserActionDef = {
|
||||||
stm: {
|
stm: {
|
||||||
mergeTo: ['normal', 'merged']
|
mergeTo: ['normal', 'merged'],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
exports.ActionDefDict = {
|
exports.ActionDefDict = {
|
||||||
userState: UserActionDef
|
userState: UserActionDef
|
||||||
|
|
|
||||||
|
|
@ -36,21 +36,21 @@ exports.desc = {
|
||||||
name: 'index_user_entity_entityId_relation',
|
name: 'index_user_entity_entityId_relation',
|
||||||
attributes: [
|
attributes: [
|
||||||
{
|
{
|
||||||
name: "userId"
|
name: "userId",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'entity'
|
name: 'entity',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'entityId'
|
name: 'entityId',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "relationId"
|
name: "relationId",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
config: {
|
config: {
|
||||||
unique: true
|
unique: true,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,29 @@ const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||||
const types_1 = require("../types");
|
const types_1 = require("../types");
|
||||||
const lodash_1 = require("../utils/lodash");
|
const lodash_1 = require("../utils/lodash");
|
||||||
const relation_1 = require("./relation");
|
const relation_1 = require("./relation");
|
||||||
|
/* function getFilterAttributes(filter: Record<string, any>) {
|
||||||
|
const attributes = [] as string[];
|
||||||
|
|
||||||
|
for (const attr in filter) {
|
||||||
|
if (attr.startsWith('$') || attr.startsWith('#')) {
|
||||||
|
if (['$and', '$or'].includes(attr)) {
|
||||||
|
for (const f of filter[attr]) {
|
||||||
|
const a = getFilterAttributes(f);
|
||||||
|
attributes.push(...a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (attr === '$not') {
|
||||||
|
const a = getFilterAttributes(filter[attr]);
|
||||||
|
attributes.push(...a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
attributes.push(attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return uniq(attributes);
|
||||||
|
} */
|
||||||
/**
|
/**
|
||||||
* 尽量合并外键的连接,防止在数据库中join的对象过多
|
* 尽量合并外键的连接,防止在数据库中join的对象过多
|
||||||
* @param entity
|
* @param entity
|
||||||
|
|
@ -1299,8 +1322,25 @@ exports.contains = contains;
|
||||||
function repel(entity, schema, filter1, filter2) {
|
function repel(entity, schema, filter1, filter2) {
|
||||||
(0, assert_1.default)(filter1);
|
(0, assert_1.default)(filter1);
|
||||||
(0, assert_1.default)(filter2);
|
(0, assert_1.default)(filter2);
|
||||||
return judgeFilterRelation(entity, schema, filter1, filter2, false);
|
/**
|
||||||
// return false;
|
* 现在的算法检查相斥有一种情况,若filter1被filter2相容,可以判断出来是false,但如果filter2被filter1相容则检查不出来
|
||||||
|
* filter1 = {
|
||||||
|
* id: 'user',
|
||||||
|
* }
|
||||||
|
* filter2 = {
|
||||||
|
id: 'user',
|
||||||
|
$$seq$$: 'xc',
|
||||||
|
* }
|
||||||
|
* 这种情况就检查不出来,所以再反向判断一次是否相容
|
||||||
|
*/
|
||||||
|
const repelled = judgeFilterRelation(entity, schema, filter1, filter2, false);
|
||||||
|
if (typeof repelled === 'boolean') {
|
||||||
|
return repelled;
|
||||||
|
}
|
||||||
|
if (contains(entity, schema, filter2, filter1) === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return repelled;
|
||||||
}
|
}
|
||||||
exports.repel = repel;
|
exports.repel = repel;
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,30 @@ import { AsyncContext } from './AsyncRowStore';
|
||||||
import { judgeRelation } from './relation';
|
import { judgeRelation } from './relation';
|
||||||
import { SyncContext } from './SyncRowStore';
|
import { SyncContext } from './SyncRowStore';
|
||||||
|
|
||||||
|
/* function getFilterAttributes(filter: Record<string, any>) {
|
||||||
|
const attributes = [] as string[];
|
||||||
|
|
||||||
|
for (const attr in filter) {
|
||||||
|
if (attr.startsWith('$') || attr.startsWith('#')) {
|
||||||
|
if (['$and', '$or'].includes(attr)) {
|
||||||
|
for (const f of filter[attr]) {
|
||||||
|
const a = getFilterAttributes(f);
|
||||||
|
attributes.push(...a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (attr === '$not') {
|
||||||
|
const a = getFilterAttributes(filter[attr]);
|
||||||
|
attributes.push(...a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
attributes.push(attr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return uniq(attributes);
|
||||||
|
} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 尽量合并外键的连接,防止在数据库中join的对象过多
|
* 尽量合并外键的连接,防止在数据库中join的对象过多
|
||||||
* @param entity
|
* @param entity
|
||||||
|
|
@ -1467,8 +1491,25 @@ export function repel<ED extends EntityDict & BaseEntityDict, T extends keyof ED
|
||||||
filter2: ED[T]['Selection']['filter']) {
|
filter2: ED[T]['Selection']['filter']) {
|
||||||
assert(filter1);
|
assert(filter1);
|
||||||
assert(filter2);
|
assert(filter2);
|
||||||
return judgeFilterRelation(entity, schema, filter1!, filter2!, false);
|
/**
|
||||||
// return false;
|
* 现在的算法检查相斥有一种情况,若filter1被filter2相容,可以判断出来是false,但如果filter2被filter1相容则检查不出来
|
||||||
|
* filter1 = {
|
||||||
|
* id: 'user',
|
||||||
|
* }
|
||||||
|
* filter2 = {
|
||||||
|
id: 'user',
|
||||||
|
$$seq$$: 'xc',
|
||||||
|
* }
|
||||||
|
* 这种情况就检查不出来,所以再反向判断一次是否相容
|
||||||
|
*/
|
||||||
|
const repelled = judgeFilterRelation(entity, schema, filter1!, filter2!, false);
|
||||||
|
if (typeof repelled === 'boolean') {
|
||||||
|
return repelled;
|
||||||
|
}
|
||||||
|
if (contains(entity, schema, filter2, filter1) === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return repelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ let rrr = repel('modi', storageSchema, {
|
||||||
id: 'ddd',
|
id: 'ddd',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assert(typeof rrr === 'object');
|
assert(rrr === false);
|
||||||
|
|
||||||
rrr = contains('modi', storageSchema, {
|
rrr = contains('modi', storageSchema, {
|
||||||
$not: {
|
$not: {
|
||||||
|
|
@ -211,7 +211,6 @@ r = contains('modiEntity', storageSchema, {
|
||||||
// {"$and":[{"$or":[{"$and":[{"id":"user","filter":{"id":"xc","$not":{"name":"xcxc"}}}]}]}]}
|
// {"$and":[{"$or":[{"$and":[{"id":"user","filter":{"id":"xc","$not":{"name":"xcxc"}}}]}]}]}
|
||||||
console.log(5, JSON.stringify(r));
|
console.log(5, JSON.stringify(r));
|
||||||
|
|
||||||
|
|
||||||
r = contains('modiEntity', storageSchema, {
|
r = contains('modiEntity', storageSchema, {
|
||||||
id: 'user',
|
id: 'user',
|
||||||
$$seq$$: 'xc',
|
$$seq$$: 'xc',
|
||||||
|
|
@ -228,7 +227,7 @@ r = contains('modiEntity', storageSchema, {
|
||||||
});
|
});
|
||||||
assert(r === false);
|
assert(r === false);
|
||||||
|
|
||||||
|
// 这个查询应当可以过滤掉modiId: 'cdcd'的条件
|
||||||
r = contains('modiEntity', storageSchema, {
|
r = contains('modiEntity', storageSchema, {
|
||||||
id: 'user',
|
id: 'user',
|
||||||
$$seq$$: 'xc',
|
$$seq$$: 'xc',
|
||||||
|
|
@ -243,6 +242,12 @@ r = contains('modiEntity', storageSchema, {
|
||||||
},
|
},
|
||||||
modiId: 'cdcd',
|
modiId: 'cdcd',
|
||||||
});
|
});
|
||||||
// 这个查询应当可以过滤掉modiId: 'cdcd'的条件
|
|
||||||
console.log(8, r);
|
r = repel('modiEntity', storageSchema, {
|
||||||
|
id: 'user',
|
||||||
|
}, {
|
||||||
|
id: 'user',
|
||||||
|
$$seq$$: 'xc',
|
||||||
|
});
|
||||||
|
console.log(9, JSON.stringify(r));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue