From cb849dc3710b919b431d22739151a2281f685c0e Mon Sep 17 00:00:00 2001 From: Vibin reddy Date: Sat, 6 Apr 2024 22:16:19 +0530 Subject: [PATCH] Fetch transactions with requestDate newest to oldest --- .../src/main/kotlin/com/chuckerteam/chucker/api/Chucker.kt | 2 +- .../data/repository/HttpTransactionDatabaseRepository.kt | 2 +- .../internal/data/repository/HttpTransactionRepository.kt | 2 +- .../chucker/internal/data/room/HttpTransactionDao.kt | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/src/main/kotlin/com/chuckerteam/chucker/api/Chucker.kt b/library/src/main/kotlin/com/chuckerteam/chucker/api/Chucker.kt index 60a1b2a7..1fc0577b 100644 --- a/library/src/main/kotlin/com/chuckerteam/chucker/api/Chucker.kt +++ b/library/src/main/kotlin/com/chuckerteam/chucker/api/Chucker.kt @@ -87,7 +87,7 @@ public object Chucker { public suspend fun generateHar(context: Context, transactionsLimit: Int = 1000): ByteArray { val transactions: List = - RepositoryProvider.transaction().getTransactions(transactionsLimit) + RepositoryProvider.transaction().getLastTransactions(transactionsLimit) val sharable = TransactionDetailsHarSharable( content = HarUtils.harStringFromTransactions( transactions, diff --git a/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionDatabaseRepository.kt b/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionDatabaseRepository.kt index 7c02bfd0..2878e3f6 100644 --- a/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionDatabaseRepository.kt +++ b/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionDatabaseRepository.kt @@ -43,5 +43,5 @@ internal class HttpTransactionDatabaseRepository(private val database: ChuckerDa override suspend fun getAllTransactions(): List = transactionDao.getAll() - override suspend fun getTransactions(limit: Int): List = transactionDao.getN(limit) + override suspend fun getLastTransactions(limit: Int): List = transactionDao.getLastN(limit) } diff --git a/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionRepository.kt b/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionRepository.kt index f8987b48..334336fd 100644 --- a/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionRepository.kt +++ b/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/repository/HttpTransactionRepository.kt @@ -27,5 +27,5 @@ internal interface HttpTransactionRepository { suspend fun getAllTransactions(): List - suspend fun getTransactions(limit: Int): List + suspend fun getLastTransactions(limit: Int): List } diff --git a/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/room/HttpTransactionDao.kt b/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/room/HttpTransactionDao.kt index 01c94127..e20637ef 100644 --- a/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/room/HttpTransactionDao.kt +++ b/library/src/main/kotlin/com/chuckerteam/chucker/internal/data/room/HttpTransactionDao.kt @@ -45,6 +45,6 @@ internal interface HttpTransactionDao { @Query("SELECT * FROM transactions") suspend fun getAll(): List - @Query("SELECT * FROM transactions LIMIT :limit") - suspend fun getN(limit: Int): List + @Query("SELECT * FROM transactions ORDER BY requestDate DESC LIMIT :limit") + suspend fun getLastN(limit: Int): List }