From 20f743932b1dae21add8b416965d07fda0782430 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 6 Jun 2024 14:36:21 -0600 Subject: [PATCH] used tags cache count fix --- lib/db/sqlite/firo_cache_coordinator.dart | 8 ++++---- lib/db/sqlite/firo_cache_reader.dart | 4 ++-- lib/electrumx_rpc/electrumx_client.dart | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/db/sqlite/firo_cache_coordinator.dart b/lib/db/sqlite/firo_cache_coordinator.dart index 83943f3cc..c0170ef85 100644 --- a/lib/db/sqlite/firo_cache_coordinator.dart +++ b/lib/db/sqlite/firo_cache_coordinator.dart @@ -50,7 +50,7 @@ abstract class FiroCacheCoordinator { static Future runFetchAndUpdateSparkUsedCoinTags( ElectrumXClient client, ) async { - final count = await FiroCacheCoordinator.getUsedCoinTagsLastAddedRowId(); + final count = await FiroCacheCoordinator.getUsedCoinTagsCount(); final unhashedTags = await client.getSparkUnhashedUsedCoinsTags( startNumber: count, ); @@ -101,14 +101,14 @@ abstract class FiroCacheCoordinator { /// Assuming the integrity of the data. Faster than actually calling count on /// a table where no records have been deleted. None should be deleted from /// this table in practice. - static Future getUsedCoinTagsLastAddedRowId() async { - final result = await _Reader._getUsedCoinTagsLastAddedRowId( + static Future getUsedCoinTagsCount() async { + final result = await _Reader._getUsedCoinTagsCount( db: _FiroCache.usedTagsCacheDB, ); if (result.isEmpty) { return 0; } - return result.first["highestId"] as int? ?? 0; + return result.first["count"] as int? ?? 0; } static Future checkTagIsUsed( diff --git a/lib/db/sqlite/firo_cache_reader.dart b/lib/db/sqlite/firo_cache_reader.dart index 10af03922..be761bc04 100644 --- a/lib/db/sqlite/firo_cache_reader.dart +++ b/lib/db/sqlite/firo_cache_reader.dart @@ -75,11 +75,11 @@ abstract class _Reader { return db.select("$query;"); } - static Future _getUsedCoinTagsLastAddedRowId({ + static Future _getUsedCoinTagsCount({ required Database db, }) async { const query = """ - SELECT MAX(id) AS highestId + SELECT COUNT(*) AS count FROM SparkUsedCoinTags; """; diff --git a/lib/electrumx_rpc/electrumx_client.dart b/lib/electrumx_rpc/electrumx_client.dart index 594e73fe3..d0a470cd1 100644 --- a/lib/electrumx_rpc/electrumx_client.dart +++ b/lib/electrumx_rpc/electrumx_client.dart @@ -954,7 +954,7 @@ class ElectrumXClient { Logging.instance.log( "Finished ElectrumXClient.getSparkUnhashedUsedCoinsTags(startNumber" - "=$startNumber). " + "=$startNumber). # of tags fetched=${tags.length}, " "Duration=${DateTime.now().difference(start)}", level: LogLevel.Info, );