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.
This commit is contained in:
2026-07-09 06:03:20 -07:00
parent 57dbe77db3
commit b3714d3b79
@@ -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<JoinedChainInfo>
@@ -172,7 +177,7 @@ abstract class ChainDao {
@Transaction
abstract suspend fun getAllChainIds(): List<String>
@Query("SELECT * FROM chains")
@Query("SELECT * FROM chains ORDER BY rowid")
@Transaction
abstract fun joinChainInfoFlow(): Flow<List<JoinedChainInfo>>