From 49db63d88803e7516399dc44edc7a252826c87fe Mon Sep 17 00:00:00 2001 From: Mononaut Date: Mon, 31 Jul 2023 16:19:51 +0900 Subject: [PATCH] Faster Redis tx deletion, fix debug log level --- backend/src/api/redis-cache.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/src/api/redis-cache.ts b/backend/src/api/redis-cache.ts index 0c256a698..fcde8013a 100644 --- a/backend/src/api/redis-cache.ts +++ b/backend/src/api/redis-cache.ts @@ -122,9 +122,10 @@ class RedisCache { async $removeTransactions(transactions: string[]) { try { await this.$ensureConnected(); - for (let i = 0; i < Math.ceil(transactions.length / 1000); i++) { - await this.client.del(transactions.slice(i * 1000, (i + 1) * 1000).map(txid => `mempool:tx:${txid}`)); - logger.info(`Deleted ${transactions.length} transactions from the Redis cache`); + for (let i = 0; i < Math.ceil(transactions.length / 10000); i++) { + const slice = transactions.slice(i * 10000, (i + 1) * 10000); + await this.client.unlink(slice.map(txid => `mempool:tx:${txid}`)); + logger.debug(`Deleted ${slice.length} transactions from the Redis cache`); } } catch (e) { logger.warn(`Failed to remove ${transactions.length} transactions from Redis cache: ${e instanceof Error ? e.message : e}`); @@ -143,7 +144,7 @@ class RedisCache { async $removeRbfEntry(type: string, txid: string): Promise { try { await this.$ensureConnected(); - await this.client.del(`rbf:${type}:${txid}`); + await this.client.unlink(`rbf:${type}:${txid}`); } catch (e) { logger.warn(`Failed to remove RBF ${type} from Redis cache: ${e instanceof Error ? e.message : e}`); }