aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/scripts/pull_missing_events.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-11-15 10:39:06 +0800
committerFred Carlsen <fred@sjelfull.no>2018-12-06 19:04:25 +0800
commit6bab2f70b956653367b046f4688d789f81de0b85 (patch)
tree84c44045650989332a48d73c4b83f654d8f9f11b /packages/pipeline/src/scripts/pull_missing_events.ts
parenta0a41b1b5d4f9bcaf4fd15ccf628e7e6b88b4621 (diff)
downloaddexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar.gz
dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.tar.zst
dexon-sol-tools-6bab2f70b956653367b046f4688d789f81de0b85.zip
Add workaround for broken save method
Diffstat (limited to 'packages/pipeline/src/scripts/pull_missing_events.ts')
-rw-r--r--packages/pipeline/src/scripts/pull_missing_events.ts22
1 files changed, 21 insertions, 1 deletions
diff --git a/packages/pipeline/src/scripts/pull_missing_events.ts b/packages/pipeline/src/scripts/pull_missing_events.ts
index f53bc12bd..2dc81f205 100644
--- a/packages/pipeline/src/scripts/pull_missing_events.ts
+++ b/packages/pipeline/src/scripts/pull_missing_events.ts
@@ -38,7 +38,27 @@ async function getExchangeEventsAsync(provider: Web3ProviderEngine): Promise<voi
const events = parseExchangeEvents(eventLogs);
console.log(`Retrieved and parsed ${events.length} total events.`);
console.log('Saving events...');
- await eventsRepository.save(events, { chunk: Math.ceil(events.length / BATCH_SAVE_SIZE) });
+ // Note(albrow): This is a temporary hack because `save` is not working as
+ // documented and is causing a foreign key constraint violation. Hopefully
+ // can remove later because this "poor man's upsert" implementation operates
+ // on one event at a time and is therefore much slower.
+ // await eventsRepository.save(events, { chunk: Math.ceil(events.length / BATCH_SAVE_SIZE) });
+ for (const event of events) {
+ try {
+ await eventsRepository.save(event);
+ } catch {
+ // Assume this is a foreign key constraint error and try doing an
+ // update instead.
+ await eventsRepository.update(
+ {
+ contractAddress: event.contractAddress,
+ blockNumber: event.blockNumber,
+ logIndex: event.logIndex,
+ },
+ event,
+ );
+ }
+ }
const totalEvents = await eventsRepository.count();
console.log(`Done saving events. There are now ${totalEvents} total events.`);
}