From b3714d3b79b6d6b7d9f8ff69b5b254c8db51d3d9 Mon Sep 17 00:00:00 2001 From: Satoshi Qazi Muhammed Date: Thu, 9 Jul 2026 06:03:20 -0700 Subject: [PATCH] fix: order chain queries by rowid so Pezkuwi's chains register first SELECT * FROM chains had no ORDER BY - SQLite gives no ordering guarantee for that, so registration/connection order across ~98 chains was effectively unpredictable per run. The merged chains.json lists Pezkuwi's own chains first (wallet-utils' merge_chains()), and CollectionDiffer's findDiff()/Room's batch insert both preserve that order on first sync, so ordering by rowid (insertion order) makes Pezkuwi's own chains reliably register and start connecting first/early, instead of being interleaved unpredictably among ~90+ Nova-inherited chains where they could end up processed dead last - observed directly: a fresh install took 45+ seconds without a single Pezkuwi-related registration/connection attempt. No user should wait minutes for their own wallet's native chain to even start syncing after install, regardless of whether the eventual outcome is correct. --- .../java/io/novafoundation/nova/core_db/dao/ChainDao.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core-db/src/main/java/io/novafoundation/nova/core_db/dao/ChainDao.kt b/core-db/src/main/java/io/novafoundation/nova/core_db/dao/ChainDao.kt index e72205a4..99017fb5 100644 --- a/core-db/src/main/java/io/novafoundation/nova/core_db/dao/ChainDao.kt +++ b/core-db/src/main/java/io/novafoundation/nova/core_db/dao/ChainDao.kt @@ -164,7 +164,12 @@ abstract class ChainDao { // ------- Queries ------ - @Query("SELECT * FROM chains") + // ORDER BY rowid: without an explicit order, SQLite gives no guarantee about row order for `SELECT *`. + // The merged chains.json lists Pezkuwi's own chains first (see wallet-utils' merge_chains()), and that + // order is what gets inserted first on initial sync - rowid tracks insertion order, so ordering by it + // means Pezkuwi's chains reliably register/connect first instead of being interleaved unpredictably + // among the ~90+ Nova-inherited chains, where they could otherwise end up processed last. + @Query("SELECT * FROM chains ORDER BY rowid") @Transaction abstract suspend fun getJoinChainInfo(): List @@ -172,7 +177,7 @@ abstract class ChainDao { @Transaction abstract suspend fun getAllChainIds(): List - @Query("SELECT * FROM chains") + @Query("SELECT * FROM chains ORDER BY rowid") @Transaction abstract fun joinChainInfoFlow(): Flow>