-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Gremlin schema sync performance
- Loading branch information
Showing
9 changed files
with
126 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 9 additions & 5 deletions
14
packages/graph-explorer/src/connector/gremlin/templates/edgesSchemaTemplate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
import edgesSchemaTemplate from "./edgesSchemaTemplate"; | ||
import { normalizeWithNoSpace as normalize } from "../../../utils/testing"; | ||
|
||
describe("Gremlin > edgesSchemaTemplate", () => { | ||
it("Should return a template with the projection of each type", () => { | ||
const template = edgesSchemaTemplate({ types: ["route", "contain"] }); | ||
|
||
expect(template).toBe( | ||
'g.E().project("route","contain")' + | ||
'.by(V().bothE("route").limit(1))' + | ||
'.by(V().bothE("contain").limit(1))' + | ||
".limit(1)" | ||
expect(normalize(template)).toBe( | ||
normalize(` | ||
g.E() | ||
.project("route", "contain") | ||
.by(V().bothE("route").limit(1)) | ||
.by(V().bothE("contain").limit(1)) | ||
.limit(1) | ||
`) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 27 additions & 7 deletions
34
packages/graph-explorer/src/connector/gremlin/templates/verticesSchemaTemplate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
import dedent from "dedent"; | ||
import { uniq } from "lodash"; | ||
|
||
/** | ||
* Given a set of nodes labels, it returns a Gremlin template that contains | ||
* one sample of each node label. | ||
* | ||
* @example | ||
* types = ["route", "contain"] | ||
* types = ["airport", "country"] | ||
* | ||
* g.V() | ||
* .project("airport","country") | ||
* .by(V().hasLabel("airport").limit(1)) | ||
* .by(V().hasLabel("country").limit(1)) | ||
* .limit(1) | ||
* .union( | ||
* __.hasLabel("airport").limit(1), | ||
* __.hasLabel("country").limit(1) | ||
* ) | ||
* .fold() | ||
* .project( | ||
* "airport", "country" | ||
* ) | ||
* .by(unfold().hasLabel("airport")) | ||
* .by(unfold().hasLabel("country")) | ||
*/ | ||
export default function verticesSchemaTemplate({ types }: { types: string[] }) { | ||
const labels = uniq(types.flatMap(type => type.split("::"))); | ||
// Labels with quotes | ||
const labels = uniq(types.flatMap(type => type.split("::"))).map( | ||
label => `"${label}"` | ||
); | ||
|
||
return `g.V().project(${labels.map(l => `"${l}"`).join(",")})${labels.map(l => `.by(V().hasLabel("${l}").limit(1))`).join("")}.limit(1)`; | ||
return dedent` | ||
g.V() | ||
.union( | ||
${labels.map(label => `__.hasLabel(${label}).limit(1)`).join(",\n ")} | ||
) | ||
.fold() | ||
.project( | ||
${labels.join(",\n ")} | ||
) | ||
${labels.map(label => `.by(unfold().hasLabel(${label}))`).join("\n ")} | ||
`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { env } from "./env"; | ||
|
||
/* | ||
# DEV NOTE | ||
This is a simple logging utility that will allow `console.log` calls any time | ||
`env.DEV === true`. This will be useful for local development and debugging. | ||
I can imagine a future where this logger has some additional functionality where | ||
it can send errors to the server and maybe allow the use to enable debug logging | ||
at runtime. | ||
*/ | ||
|
||
export default { | ||
/** Calls `console.log` if the app is running in DEV mode. */ | ||
log(message?: any, ...optionalParams: any[]) { | ||
env.DEV && console.log(message, optionalParams); | ||
}, | ||
/** Calls `console.warn`. */ | ||
warn(message?: any, ...optionalParams: any[]) { | ||
console.warn(message, optionalParams); | ||
}, | ||
/** Calls `console.error`. */ | ||
error(message?: any, ...optionalParams: any[]) { | ||
console.error(message, optionalParams); | ||
}, | ||
}; |