Skip to content

Commit 8e97610

Browse files
committed
chore(flipcash/pools): order by the timestamp relative to open or closed
sort by created timestamp for open, closed timestamp for closed Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent c979424 commit 8e97610

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

  • apps/flipcash/shared/persistence/db/src/main/kotlin/com/flipcash/app/persistence/dao

apps/flipcash/shared/persistence/db/src/main/kotlin/com/flipcash/app/persistence/dao/PoolDao.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,23 @@ interface PoolDao {
7777
@Query("SELECT * FROM pool_metadata ORDER BY timestamp DESC")
7878
suspend fun getAll(): List<PoolWithBetsEntity>
7979

80-
@Query("SELECT * FROM pool_metadata ORDER BY isOpen DESC, timestamp DESC")
80+
@Query(
81+
"""
82+
SELECT * FROM pool_metadata
83+
ORDER BY isOpen DESC,
84+
CASE WHEN isOpen THEN timestamp ELSE closedTimestamp END DESC
85+
"""
86+
)
8187
fun observePools(): PagingSource<Int, PoolEntity>
8288

83-
@Query("SELECT * FROM pool_metadata WHERE idBase58 = :id ORDER BY timestamp DESC")
89+
@Query("SELECT * FROM pool_metadata WHERE idBase58 = :id")
8490
fun observe(id: String): Flow<PoolWithBetsEntity?>
8591
fun observe(id: ID): Flow<PoolWithBetsEntity?> {
8692
return observe(id.base58)
8793
}
8894

8995
@Transaction
90-
@Query("SELECT * FROM pool_metadata WHERE idBase58 = :id ORDER BY timestamp DESC")
96+
@Query("SELECT * FROM pool_metadata WHERE idBase58 = :id")
9197
suspend fun getPoolWithBets(id: String): PoolWithBetsEntity?
9298
suspend fun getPoolWithBets(id: ID): PoolWithBetsEntity? {
9399
return getPoolWithBets(id.base58)

0 commit comments

Comments
 (0)