From a4cb6fcb8c038a61c24e9589bb6f2b6c7cfe465f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 16 Jan 2024 09:45:26 +0100 Subject: [PATCH 1/3] fix: setup a no-op PG client in dry-run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- bin/dry-run.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/dry-run.js b/bin/dry-run.js index bc926aad..e947c998 100644 --- a/bin/dry-run.js +++ b/bin/dry-run.js @@ -99,6 +99,7 @@ await evaluate({ fetchRoundDetails, ieContractWithSigner, logger: console, + createPgClient, recordTelemetry }) @@ -209,3 +210,14 @@ async function fetchMeasurementsAddedFromChain (roundIndex) { return events.filter(e => e.roundIndex.eq(roundIndex)).map(e => e.cid) } + +function createPgClient () { + return { + async query () { + return { rows: [] } + }, + async end () { + // no-op + } + } +} From 70ee0e4a9b0b6060dad822fbd2e1cf86d980836c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 16 Jan 2024 17:13:28 +0100 Subject: [PATCH 2/3] fixup! add code comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- bin/dry-run.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/dry-run.js b/bin/dry-run.js index e947c998..99a262cc 100644 --- a/bin/dry-run.js +++ b/bin/dry-run.js @@ -99,8 +99,12 @@ await evaluate({ fetchRoundDetails, ieContractWithSigner, logger: console, - createPgClient, - recordTelemetry + recordTelemetry, + + // We don't want dry runs to update data in `sparks_stats`, therefore we are passing a stub + // connection factory that creates no-op clients. This also keeps the setup simpler. The person + // executing a dry run does not need access to any Postgres instance. + createPgClient: createNoopPgClient }) console.log(process.memoryUsage()) @@ -211,7 +215,7 @@ async function fetchMeasurementsAddedFromChain (roundIndex) { return events.filter(e => e.roundIndex.eq(roundIndex)).map(e => e.cid) } -function createPgClient () { +function createNoopPgClient () { return { async query () { return { rows: [] } From 7b451bb4e13032a691d378e2ad164501fda19720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Wed, 17 Jan 2024 10:01:06 +0100 Subject: [PATCH 3/3] fixup! comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- bin/dry-run.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/dry-run.js b/bin/dry-run.js index 99a262cc..d856d104 100644 --- a/bin/dry-run.js +++ b/bin/dry-run.js @@ -104,6 +104,8 @@ await evaluate({ // We don't want dry runs to update data in `sparks_stats`, therefore we are passing a stub // connection factory that creates no-op clients. This also keeps the setup simpler. The person // executing a dry run does not need access to any Postgres instance. + // Evaluate uses the PG client only for updating the statistics, it's not reading any data. + // Thus it's safe to inject a no-op client. createPgClient: createNoopPgClient })