From bfa5ad9d22761dc9cf5a393f85897d2431292f45 Mon Sep 17 00:00:00 2001 From: michael1011 Date: Sun, 8 Oct 2023 23:15:15 +0200 Subject: [PATCH] perf: add indexes for queried database columns --- lib/db/models/ReverseSwap.ts | 12 ++++++++++++ lib/db/models/Swap.ts | 12 ++++++++++++ test/unit/notifications/ExampleSwaps.ts | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/db/models/ReverseSwap.ts b/lib/db/models/ReverseSwap.ts index 30f041b22..dd5d210a2 100644 --- a/lib/db/models/ReverseSwap.ts +++ b/lib/db/models/ReverseSwap.ts @@ -156,6 +156,10 @@ class ReverseSwap extends Model implements ReverseSwapType { unique: true, fields: ['id'], }, + { + unique: false, + fields: ['status'], + }, { unique: true, fields: ['preimageHash'], @@ -172,6 +176,14 @@ class ReverseSwap extends Model implements ReverseSwapType { unique: false, fields: ['referral'], }, + { + unique: false, + fields: ['lockupAddress'], + }, + { + unique: false, + fields: ['transactionId'], + }, ], }, ); diff --git a/lib/db/models/Swap.ts b/lib/db/models/Swap.ts index 2a736a0c1..400ea8f7c 100644 --- a/lib/db/models/Swap.ts +++ b/lib/db/models/Swap.ts @@ -119,6 +119,10 @@ class Swap extends Model implements SwapType { unique: true, fields: ['id'], }, + { + unique: false, + fields: ['status'], + }, { unique: true, fields: ['preimageHash'], @@ -131,6 +135,14 @@ class Swap extends Model implements SwapType { unique: false, fields: ['referral'], }, + { + unique: false, + fields: ['lockupAddress'], + }, + { + unique: false, + fields: ['lockupTransactionId'], + }, ], }, ); diff --git a/test/unit/notifications/ExampleSwaps.ts b/test/unit/notifications/ExampleSwaps.ts index c43828778..6d27ca884 100644 --- a/test/unit/notifications/ExampleSwaps.ts +++ b/test/unit/notifications/ExampleSwaps.ts @@ -37,6 +37,7 @@ export const pendingSwapExample: SwapType = { id: '654321', status: SwapUpdateEvent.SwapCreated, + lockupAddress: 'bcrt1q4fgsuxk4q0uhmqm4hlhwz2kv4k374f5ta2dqn3', preimageHash: 'c77376aa6798bf9dea9d8b2f1a08151469d3823faca22d32ac6cf00a24261870', invoice: @@ -79,6 +80,7 @@ export const pendingReverseSwapExample = { '5b2dc635c50a25de79b86be956db2fbc6a17e36d2562f1185aca3522a5a9edf6', invoice: 'lnbcrt1p0xqpt2pp5l34c2393chx7eut4hvlt6h0333nfa562quksdqnx8ymd437dw5msdqqcqzpgsp5f88p6pf23hrn5l7j5sp0q26vtdzzfr838njchzc3lfp6xq2nnj0q9qy9qsq33agd2syjgxjkf6mshm5x482hsu99k2ukrv27wvgtatyzw0lgs83pc0yd3fmwgcn5kcav47h4483qqz9yh4w0vegzlq3cv7zcxssm2sp7l2rck', + lockupAddress: '2Mv9up2W4ADfj4Dm9EtfCCPSwgfwTp8Sy98', }; export const channelSwapExample: SwapType = { @@ -94,7 +96,7 @@ export const channelSwapExample: SwapType = { onchainAmount: 1000000, timeoutBlockHeight: 123, status: SwapUpdateEvent.TransactionClaimed, - lockupAddress: 'bcrt1q4fgsuxk4q0uhmqm4hlhwz2kv4k374f5ta2dqn2', + lockupAddress: 'bcrt1q4fgsuxk4q0uhmqm4hlhwz2kv4k374f5ta2dqn4', lockupTransactionId: '6071400d052ffd911f47537aba80500d52f67077a8522ec6915c128228f71a69', preimageHash: