Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V5 logical operator filter performance optimization #212

Open
wants to merge 2 commits into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@babel/plugin-transform-runtime": "^7.23.3",
"@babel/preset-env": "^7.22.14",
"@babel/preset-typescript": "^7.22.11",
"@dataplan/pg": "^0.0.1-beta.14",
"@dataplan/pg": "^0.0.1-beta.22",
"@tsconfig/node16": "^1.0.3",
"@types/jest": "29.5.0",
"@typescript-eslint/eslint-plugin": "^6.5.0",
Expand All @@ -49,18 +49,18 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-tsdoc": "^0.2.17",
"eslint_d": "^12.2.1",
"grafast": "^0.1.1-beta.3",
"grafserv": "^0.1.1-beta.5",
"graphile-build": "^5.0.0-beta.1",
"graphile-build-pg": "^5.0.0-beta.17",
"graphile-export": "^0.0.2-beta.8",
"grafast": "^0.1.1-beta.11",
"grafserv": "^0.1.1-beta.13",
"graphile-build": "^5.0.0-beta.21",
"graphile-build-pg": "^5.0.0-beta.25",
"graphile-export": "^0.0.2-beta.16",
"graphql": "16.1.0-experimental-stream-defer.6",
"jest": "29.7.0",
"module-from-string": "^3.3.0",
"pg": "8.11.3",
"pg-introspection": "^0.0.1-beta.5",
"pg-sql2": "^5.0.0-beta.4",
"postgraphile": "^5.0.0-beta.18",
"pg-sql2": "^5.0.0-beta.6",
"postgraphile": "^5.0.0-beta.26",
"prettier": "2.8.7",
"ts-jest": "29.1.0",
"typescript": "^5.0.4"
Expand Down
7 changes: 6 additions & 1 deletion src/PgConnectionArgFilterAttributesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ export const PgConnectionArgFilterAttributesPlugin: GraphileConfig.Plugin = {
}
const $col = new PgConditionStep($where);
$col.extensions.pgFilterAttribute = colSpec;
fieldArgs.apply($col);
const value = $raw.eval();
for (const key in value) {
if (value[key] !== undefined) {
fieldArgs.apply($col, [key]);
}
}
},
[
PgConditionStep,
Expand Down
27 changes: 23 additions & 4 deletions src/PgConnectionArgFilterLogicalOperatorsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ export const PgConnectionArgFilterLogicalOperatorsPlugin: GraphileConfig.Plugin
const $and = $where.andPlan();
// No need for this more correct form, easier to read if it's flatter.
// fieldArgs.apply(() => $and.andPlan());
fieldArgs.apply($and);
const value = fieldArgs.getRaw().eval();
for (let i = 0; i < value.length; i++) {
for (const key in value[i]) {
if (value[i][key] !== undefined) {
fieldArgs.apply($and, [i, key]);
}
}
}
},
[assertAllowed]
),
Expand All @@ -65,9 +72,16 @@ export const PgConnectionArgFilterLogicalOperatorsPlugin: GraphileConfig.Plugin
(assertAllowed) =>
function ($where: PgConditionStep<any>, fieldArgs) {
assertAllowed(fieldArgs, "list");
const value = fieldArgs.getRaw().eval();
const $or = $where.orPlan();
// Every entry is added to the `$or`, but the entries themselves should use an `and`.
fieldArgs.apply(() => $or.andPlan());
for (let i = 0; i < value.length; i++) {
for (const key in value[i]) {
if (value[i][key] !== undefined) {
// Every entry is added to the `$or`, but the entries themselves should use an `and`.
fieldArgs.apply(() => $or.andPlan(), [i, key]);
}
}
}
},
[assertAllowed]
),
Expand All @@ -87,7 +101,12 @@ export const PgConnectionArgFilterLogicalOperatorsPlugin: GraphileConfig.Plugin
assertAllowed(fieldArgs, "object");
const $not = $where.notPlan();
const $and = $not.andPlan();
fieldArgs.apply($and);
const value = fieldArgs.getRaw().eval();
for (const key in value) {
if (value[key] !== undefined) {
fieldArgs.apply($and, [key]);
}
}
},
[assertAllowed]
),
Expand Down
14 changes: 12 additions & 2 deletions src/PgConnectionArgFilterPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,12 @@ export const PgConnectionArgFilterPlugin: GraphileConfig.Plugin = {
codec: attributeCodec,
};
}
fieldArgs.apply($where);
const value = fieldArgs.getRaw().eval();
for (const key in value) {
if (value[key] !== undefined) {
fieldArgs.apply($where, [key]);
}
}
},
[assertAllowed, attributeCodec]
),
Expand All @@ -508,7 +513,12 @@ export const PgConnectionArgFilterPlugin: GraphileConfig.Plugin = {
codec: attributeCodec,
};
}
fieldArgs.apply($where);
const value = fieldArgs.getRaw().eval();
for (const key in value) {
if (value[key] !== undefined) {
fieldArgs.apply($where, [key]);
}
}
},
[assertAllowed, attributeCodec]
),
Expand Down
Loading