fix caching of instance defaults and emojis (#2643)
* fix caching of instance defaults and emojis * use correct OnConflictStrategy * rename dao methods
This commit is contained in:
parent
1c11671f3e
commit
1fed84f948
|
@ -45,7 +45,7 @@ class InstanceInfoRepository @Inject constructor(
|
||||||
*/
|
*/
|
||||||
suspend fun getEmojis(): List<Emoji> = withContext(Dispatchers.IO) {
|
suspend fun getEmojis(): List<Emoji> = withContext(Dispatchers.IO) {
|
||||||
api.getCustomEmojis()
|
api.getCustomEmojis()
|
||||||
.onSuccess { emojiList -> dao.insertOrReplace(EmojisEntity(instanceName, emojiList)) }
|
.onSuccess { emojiList -> dao.upsert(EmojisEntity(instanceName, emojiList)) }
|
||||||
.getOrElse { throwable ->
|
.getOrElse { throwable ->
|
||||||
Log.w(TAG, "failed to load custom emojis, falling back to cache", throwable)
|
Log.w(TAG, "failed to load custom emojis, falling back to cache", throwable)
|
||||||
dao.getEmojiInfo(instanceName)?.emojiList.orEmpty()
|
dao.getEmojiInfo(instanceName)?.emojiList.orEmpty()
|
||||||
|
@ -78,7 +78,7 @@ class InstanceInfoRepository @Inject constructor(
|
||||||
maxFieldNameLength = instance.pleroma?.metadata?.fieldLimits?.nameLength,
|
maxFieldNameLength = instance.pleroma?.metadata?.fieldLimits?.nameLength,
|
||||||
maxFieldValueLength = instance.pleroma?.metadata?.fieldLimits?.valueLength
|
maxFieldValueLength = instance.pleroma?.metadata?.fieldLimits?.valueLength
|
||||||
)
|
)
|
||||||
dao.insertOrReplace(instanceEntity)
|
dao.upsert(instanceEntity)
|
||||||
instanceEntity
|
instanceEntity
|
||||||
},
|
},
|
||||||
{ throwable ->
|
{ throwable ->
|
||||||
|
|
|
@ -20,15 +20,37 @@ import androidx.room.Insert
|
||||||
import androidx.room.OnConflictStrategy
|
import androidx.room.OnConflictStrategy
|
||||||
import androidx.room.Query
|
import androidx.room.Query
|
||||||
import androidx.room.RewriteQueriesToDropUnusedColumns
|
import androidx.room.RewriteQueriesToDropUnusedColumns
|
||||||
|
import androidx.room.Transaction
|
||||||
|
import androidx.room.Update
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface InstanceDao {
|
interface InstanceDao {
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE, entity = InstanceEntity::class)
|
@Insert(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class)
|
||||||
suspend fun insertOrReplace(instance: InstanceInfoEntity)
|
suspend fun insertOrIgnore(instance: InstanceInfoEntity): Long
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE, entity = InstanceEntity::class)
|
@Update(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class)
|
||||||
suspend fun insertOrReplace(emojis: EmojisEntity)
|
suspend fun updateOrIgnore(instance: InstanceInfoEntity)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
suspend fun upsert(instance: InstanceInfoEntity) {
|
||||||
|
if (insertOrIgnore(instance) == -1L) {
|
||||||
|
updateOrIgnore(instance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class)
|
||||||
|
suspend fun insertOrIgnore(emojis: EmojisEntity): Long
|
||||||
|
|
||||||
|
@Update(onConflict = OnConflictStrategy.IGNORE, entity = InstanceEntity::class)
|
||||||
|
suspend fun updateOrIgnore(emojis: EmojisEntity)
|
||||||
|
|
||||||
|
@Transaction
|
||||||
|
suspend fun upsert(emojis: EmojisEntity) {
|
||||||
|
if (insertOrIgnore(emojis) == -1L) {
|
||||||
|
updateOrIgnore(emojis)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@RewriteQueriesToDropUnusedColumns
|
@RewriteQueriesToDropUnusedColumns
|
||||||
@Query("SELECT * FROM InstanceEntity WHERE instance = :instance LIMIT 1")
|
@Query("SELECT * FROM InstanceEntity WHERE instance = :instance LIMIT 1")
|
||||||
|
|
Loading…
Reference in New Issue