From 10be37c78ea04e44736da525d062eeb235109eb5 Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Wed, 3 Mar 2021 16:12:17 -1000 Subject: [PATCH 1/2] Little logging cleanup --- backend/rds.ts | 2 +- pages/api/replicache-pull.ts | 10 +++++----- pages/api/replicache-push.ts | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/backend/rds.ts b/backend/rds.ts index 37f6d3f..36df499 100644 --- a/backend/rds.ts +++ b/backend/rds.ts @@ -154,7 +154,7 @@ async function executeStatementInDatabase( name, value, })); - console.log("Executing", database, sql, params); + console.log("Executing", database, sql, JSON.stringify(params, null, '')); const command = new ExecuteStatementCommand({ database: database ?? "", resourceArn, diff --git a/pages/api/replicache-pull.ts b/pages/api/replicache-pull.ts index 1f9df3b..a15abab 100644 --- a/pages/api/replicache-pull.ts +++ b/pages/api/replicache-pull.ts @@ -6,12 +6,12 @@ import { getCookieVersion, getLastMutationID } from "../../backend/data"; import { must } from "../../backend/decode"; export default async (req: NextApiRequest, res: NextApiResponse) => { - console.log(`Processing pull`, req.body); + console.log(`Processing pull`, JSON.stringify(req.body, null, '')); const pull = must(pullRequest.decode(req.body)); let cookie = pull.baseStateID === "" ? 0 : parseInt(pull.baseStateID); - console.time(`Reading all objects...`); + const t0 = Date.now(); let entries; let lastMutationID = 0; @@ -24,8 +24,8 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { getCookieVersion(executor), ]); }); - console.log({ lastMutationID }); - console.timeEnd(`Reading all objects...`); + console.log('lastMutationID: ', lastMutationID); + console.log('Read all objects in', Date.now() - t0); // Grump. Typescript seems to not understand that the argument to transact() // is guaranteed to have been called before transact() exits. @@ -68,7 +68,7 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { } } - console.log(`Returning`, resp); + console.log(`Returning`, JSON.stringify(resp, null, '')); res.json(resp); res.end(); }; diff --git a/pages/api/replicache-push.ts b/pages/api/replicache-push.ts index 681f34c..86fc2a6 100644 --- a/pages/api/replicache-push.ts +++ b/pages/api/replicache-push.ts @@ -72,17 +72,18 @@ type Mutation = t.TypeOf; export default async (req: NextApiRequest, res: NextApiResponse) => { const push = must(pushRequest.decode(req.body)); - console.log("Processing push", push); + console.log("Processing push", JSON.stringify(push, null, '')); + const t0 = Date.now(); for (let i = 0; i < push.mutations.length; i++) { await transact(async (executor) => { let lastMutationID = await getLastMutationID(executor, push.clientID); - console.log({ lastMutationID }); + console.log('lastMutationID:', lastMutationID); // Scan forward from here collapsing any collapsable mutations. for (; i < push.mutations.length; i++) { let mutation = push.mutations[i]; - console.log({ mutation }); + console.log('mutation:', JSON.stringify(mutation, null, '')); const expectedMutationID = lastMutationID + 1; if (mutation.id < expectedMutationID) { @@ -99,16 +100,17 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { } const next = push.mutations[i + 1]; - console.log("Considering for collapse", mutation, next); + console.log("Considering for collapse", JSON.stringify(mutation, null, ''), JSON.stringify(next, null, '')); if (next) { if (collapse(mutation, next)) { lastMutationID = mutation.id; - console.log("Collapsed into", next); + console.log("Collapsed into", JSON.stringify(next, null, '')); continue; } } const s = storage(executor); + const t1 = Date.now(); switch (mutation.name) { case "moveShape": @@ -129,12 +131,14 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { } await setLastMutationID(executor, push.clientID, expectedMutationID); - + console.log('Processed mutation in', Date.now() - t1); break; } }); } + console.log('Processed all mutations in', Date.now() - t0); + const pusher = new Pusher({ appId: "1157097", key: "d9088b47d2371d532c4c", @@ -142,9 +146,10 @@ export default async (req: NextApiRequest, res: NextApiResponse) => { cluster: "us3", useTLS: true, }); - console.time(`sending poke...`); + + const t2 = Date.now(); await pusher.trigger("default", "poke", {}); - console.timeEnd(`sending poke...`); + console.log('Sent poke in', Date.now() - t2); res.status(200).json({}); }; From 0d5009c8946e61caa77510e912a77ca8c7cd398b Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Wed, 3 Mar 2021 16:12:46 -1000 Subject: [PATCH 2/2] Remove duplicate extraneous push at startup. --- pages/index.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/pages/index.tsx b/pages/index.tsx index d6a92bc..50dd0b1 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -34,7 +34,6 @@ export default function Home() { id: d.clientID, defaultUserInfo, }); - rep.sync(); Pusher.logToConsole = true; var pusher = new Pusher("d9088b47d2371d532c4c", {