加强了filterRepel的判定
This commit is contained in:
parent
7741fca86b
commit
87d8ea3761
|
|
@ -31,12 +31,12 @@ exports.desc = {
|
|||
name: 'index_entity_relation',
|
||||
attributes: [
|
||||
{
|
||||
name: 'destEntity'
|
||||
name: 'destEntity',
|
||||
},
|
||||
{
|
||||
name: "relationId"
|
||||
name: "relationId",
|
||||
},
|
||||
]
|
||||
],
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,15 +45,15 @@ exports.desc = {
|
|||
name: 'namespace_language',
|
||||
attributes: [
|
||||
{
|
||||
name: 'namespace'
|
||||
name: 'namespace',
|
||||
},
|
||||
{
|
||||
name: 'language'
|
||||
name: 'language',
|
||||
}
|
||||
],
|
||||
config: {
|
||||
unique: true
|
||||
}
|
||||
unique: true,
|
||||
},
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ exports.ActionDefDict = exports.actions = void 0;
|
|||
const IActionDef = {
|
||||
stm: {
|
||||
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.ActionDefDict = {
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ exports.desc = {
|
|||
attributes: [
|
||||
{
|
||||
name: 'iState',
|
||||
direction: 'ASC'
|
||||
direction: 'ASC',
|
||||
}
|
||||
]
|
||||
],
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -37,18 +37,18 @@ exports.desc = {
|
|||
name: 'index_targetEntity_entityId_name',
|
||||
attributes: [
|
||||
{
|
||||
name: 'entity'
|
||||
name: 'entity',
|
||||
},
|
||||
{
|
||||
name: 'entityId'
|
||||
name: 'entityId',
|
||||
},
|
||||
{
|
||||
name: 'name'
|
||||
name: 'name',
|
||||
}
|
||||
],
|
||||
config: {
|
||||
unique: true
|
||||
}
|
||||
unique: true,
|
||||
},
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,18 +29,18 @@ exports.desc = {
|
|||
name: 'index_entity_relation_path',
|
||||
attributes: [
|
||||
{
|
||||
name: "sourceRelationId"
|
||||
name: "sourceRelationId",
|
||||
},
|
||||
{
|
||||
name: 'path'
|
||||
name: 'path',
|
||||
},
|
||||
{
|
||||
name: "destRelationId"
|
||||
name: "destRelationId",
|
||||
},
|
||||
],
|
||||
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"];
|
||||
const UserActionDef = {
|
||||
stm: {
|
||||
mergeTo: ['normal', 'merged']
|
||||
}
|
||||
mergeTo: ['normal', 'merged'],
|
||||
},
|
||||
};
|
||||
exports.ActionDefDict = {
|
||||
userState: UserActionDef
|
||||
|
|
|
|||
|
|
@ -36,21 +36,21 @@ exports.desc = {
|
|||
name: 'index_user_entity_entityId_relation',
|
||||
attributes: [
|
||||
{
|
||||
name: "userId"
|
||||
name: "userId",
|
||||
},
|
||||
{
|
||||
name: 'entity'
|
||||
name: 'entity',
|
||||
},
|
||||
{
|
||||
name: 'entityId'
|
||||
name: 'entityId',
|
||||
},
|
||||
{
|
||||
name: "relationId"
|
||||
name: "relationId",
|
||||
},
|
||||
],
|
||||
config: {
|
||||
unique: true
|
||||
}
|
||||
unique: true,
|
||||
},
|
||||
}
|
||||
]
|
||||
};
|
||||
|
|
|
|||
|
|
@ -6,6 +6,29 @@ const assert_1 = tslib_1.__importDefault(require("assert"));
|
|||
const types_1 = require("../types");
|
||||
const lodash_1 = require("../utils/lodash");
|
||||
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的对象过多
|
||||
* @param entity
|
||||
|
|
@ -1299,8 +1322,25 @@ exports.contains = contains;
|
|||
function repel(entity, schema, filter1, filter2) {
|
||||
(0, assert_1.default)(filter1);
|
||||
(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;
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,6 +6,30 @@ import { AsyncContext } from './AsyncRowStore';
|
|||
import { judgeRelation } from './relation';
|
||||
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的对象过多
|
||||
* @param entity
|
||||
|
|
@ -1467,8 +1491,25 @@ export function repel<ED extends EntityDict & BaseEntityDict, T extends keyof ED
|
|||
filter2: ED[T]['Selection']['filter']) {
|
||||
assert(filter1);
|
||||
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',
|
||||
}
|
||||
});
|
||||
assert(typeof rrr === 'object');
|
||||
assert(rrr === false);
|
||||
|
||||
rrr = contains('modi', storageSchema, {
|
||||
$not: {
|
||||
|
|
@ -211,7 +211,6 @@ r = contains('modiEntity', storageSchema, {
|
|||
// {"$and":[{"$or":[{"$and":[{"id":"user","filter":{"id":"xc","$not":{"name":"xcxc"}}}]}]}]}
|
||||
console.log(5, JSON.stringify(r));
|
||||
|
||||
|
||||
r = contains('modiEntity', storageSchema, {
|
||||
id: 'user',
|
||||
$$seq$$: 'xc',
|
||||
|
|
@ -228,7 +227,7 @@ r = contains('modiEntity', storageSchema, {
|
|||
});
|
||||
assert(r === false);
|
||||
|
||||
|
||||
// 这个查询应当可以过滤掉modiId: 'cdcd'的条件
|
||||
r = contains('modiEntity', storageSchema, {
|
||||
id: 'user',
|
||||
$$seq$$: 'xc',
|
||||
|
|
@ -243,6 +242,12 @@ r = contains('modiEntity', storageSchema, {
|
|||
},
|
||||
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