Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sn-2913 pool cache #199

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface AssetDao {
private const val QUERY_ASSET_TOKEN_ACTIVE = """
select * from assets inner join ($joinFiatToken) tokensfiats on assets.tokenId=tokensfiats.id
where assets.accountAddress=:address and tokensfiats.whitelistName=:whitelist
and ((assets.visibility=1 or assets.displayAsset=1 or tokensfiats.isHidable = 0) or (tokensfiats.id in (select userTokenIdTarget from userpools)) or (tokensfiats.id in (select tokenId from poolBaseTokens))) order by assets.position
and ((assets.visibility=1 or assets.displayAsset=1 or tokensfiats.isHidable = 0) or (tokensfiats.id in (select tokenIdTarget from allpools)) or (tokensfiats.id in (select tokenId from poolBaseTokens))) order by assets.position
"""
}

Expand Down
9 changes: 8 additions & 1 deletion core_db/src/main/java/jp/co/soramitsu/core_db/dao/PoolDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package jp.co.soramitsu.core_db.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
Expand Down Expand Up @@ -63,7 +64,10 @@ interface PoolDao {
select * from allpools where tokenIdBase=:base and tokenIdTarget=:target
"""
)
fun getBasicPool(base: String, target: String): BasicPoolLocal?
suspend fun getBasicPool(base: String, target: String): BasicPoolLocal?

@Query("select * from allpools")
suspend fun getBasicPools(): List<BasicPoolLocal>

@Query("select * from poolBaseTokens left join tokens on poolBaseTokens.tokenId = tokens.id")
suspend fun getPoolBaseTokens(): List<BasePoolWithTokenLocal>
Expand Down Expand Up @@ -106,6 +110,9 @@ interface PoolDao {
)
fun subscribePool(assetId: String, baseTokenId: String): Flow<List<UserPoolJoinedLocalNullable>>

@Delete
suspend fun deleteBasicPools(p: List<BasicPoolLocal>)

@Upsert()
suspend fun insertBasicPools(pools: List<BasicPoolLocal>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ class PolkaswapSubscriptionRepositoryImpl @Inject constructor(
}
}
}
val minus = db.poolDao().getBasicPools().filter { db ->
list.find { it.tokenIdBase == db.tokenIdBase && it.tokenIdTarget == db.tokenIdTarget } == null
}
db.poolDao().deleteBasicPools(minus)
db.poolDao().insertBasicPools(list)
}

Expand Down