diff --git a/android/app/src/main/java/com/fabledsword/minstrel/cache/mutations/MutationReplayer.kt b/android/app/src/main/java/com/fabledsword/minstrel/cache/mutations/MutationReplayer.kt index 6d08a5f8..a09c1301 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/cache/mutations/MutationReplayer.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/cache/mutations/MutationReplayer.kt @@ -135,15 +135,18 @@ class MutationReplayer @Inject constructor( private fun supersededLikeToggleIds(rows: List): Set { val latestByEntity = HashMap() val superseded = HashSet() - for (row in rows) { - if (row.kind != MutationKind.LIKE_TOGGLE) continue - val decoded = runCatching { - json.decodeFromString(LikeTogglePayload.serializer(), row.payload) - }.getOrNull() ?: continue - val key = "${decoded.entityType}:${decoded.entityId}" - // `rows` is ascending by id, so a prior entry is always older. - latestByEntity.put(key, row.id)?.let(superseded::add) - } + rows.asSequence() + .filter { it.kind == MutationKind.LIKE_TOGGLE } + .forEach { row -> + val decoded = runCatching { + json.decodeFromString(LikeTogglePayload.serializer(), row.payload) + }.getOrNull() + if (decoded != null) { + val key = "${decoded.entityType}:${decoded.entityId}" + // `rows` is ascending by id, so a prior entry is always older. + latestByEntity.put(key, row.id)?.let(superseded::add) + } + } return superseded }