mirror: add typename support to query plan (#1663)

Summary:
The internal `QueryPlan` structure now lists IDs of objects whose
typename is to be queried. This list is expected to be empty for now.

Test Plan:
Unit tests included.

wchargin-branch: mirror-typename-queryplan
This commit is contained in:
William Chargin 2020-02-29 16:56:20 -08:00 committed by GitHub
parent b36ecb4d9a
commit 477243fc2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -536,6 +536,9 @@ export class Mirror {
_findOutdated(since: Date): QueryPlan {
const db = this._db;
return _inTransaction(db, () => {
// All objects must have recorded typenames due to the `NOT NULL`
// constraint on `typename` column of the `objects` table.
const typenames: $PropertyType<QueryPlan, "typenames"> = [];
const objects: $PropertyType<QueryPlan, "objects"> = db
.prepare(
dedent`\
@ -575,7 +578,7 @@ export class Mirror {
delete result.neverUpdated;
return result;
});
return {objects, connections};
return {typenames, objects, connections};
});
}
@ -605,6 +608,9 @@ export class Mirror {
+connectionPageSize: number,
|}
): Queries.Selection[] {
if (queryPlan.typenames.length > 0) {
throw new Error("Typename queries not yet supported");
}
// Group objects by type, so that we have to specify each type's
// fieldset fewer times (only once per `nodesOfTypeLimit` nodes
// instead of for every node).
@ -2051,6 +2057,7 @@ type NetworkLogId = number;
* A set of objects and connections that should be updated.
*/
type QueryPlan = {|
+typenames: $ReadOnlyArray<Schema.ObjectId>,
+objects: $ReadOnlyArray<{|
+typename: Schema.Typename,
+id: Schema.ObjectId,

View File

@ -566,6 +566,7 @@ describe("graphql/mirror", () => {
const actual = mirror._findOutdated(new Date(midUpdate.time));
const expected = {
typenames: [],
objects: [
{typename: "Repository", id: "repo:ab/cd"}, // loaded before cutoff
// issue:ab/cd#1 was loaded after the cutoff
@ -608,6 +609,7 @@ describe("graphql/mirror", () => {
const db = new Database(":memory:");
const mirror = new Mirror(db, buildGithubSchema());
const plan = {
typenames: [],
objects: [],
connections: [
{
@ -636,10 +638,28 @@ describe("graphql/mirror", () => {
'"Issue" vs. "Repository"'
);
});
it("errors if given any typename requests", () => {
const db = new Database(":memory:");
const mirror = new Mirror(db, buildGithubSchema());
const plan = {
typenames: ["hmmm"],
objects: [],
connections: [],
};
expect(() => {
mirror._queryFromPlan(plan, {
nodesLimit: 10,
nodesOfTypeLimit: 5,
connectionLimit: 5,
connectionPageSize: 23,
});
}).toThrow("Typename queries not yet supported");
});
it("creates a good query", () => {
const db = new Database(":memory:");
const mirror = new Mirror(db, buildGithubSchema());
const plan = {
typenames: [],
objects: [
{typename: "Issue", id: "i#1"},
{typename: "Repository", id: "repo#2"},
@ -1136,6 +1156,7 @@ describe("graphql/mirror", () => {
spyFindOutdated.mock.results[1].value
);
expect(spyFindOutdated.mock.results[2].value).toEqual({
typenames: [],
objects: [],
connections: [],
});