Skip to content

Commit 1dd3050

Browse files
committed
fix: proper order of storage handling - prefer fresh
1 parent 7c3e189 commit 1dd3050

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

core/src/commonMain/kotlin/io/tolgee/api/TolgeeApi.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,16 @@ internal data object TolgeeApi {
5858
?: return TranslationEmpty
5959
val path = config.contentDelivery.path(language)
6060

61-
storage?.get(path)?.decodeToString()?.decodeTranslation(config, language)?.let { return it }
61+
val fresh = getTranslationFromCDN(client, config, path)
62+
val decoded = fresh?.decodeTranslation(config, language)
6263

63-
val fresh = getTranslationFromCDN(client, config, path) ?: return TranslationEmpty
64-
val decoded = fresh.decodeTranslation(config, language) ?: return TranslationEmpty
64+
if (decoded != null) {
65+
storage?.put(path, fresh.toByteArray())
66+
return decoded
67+
}
6568

66-
storage?.put(path, fresh.toByteArray())
67-
68-
return decoded
69+
val cached = storage?.get(path)?.decodeToString()?.decodeTranslation(config, language)
70+
return cached ?: TranslationEmpty
6971
}
7072

7173
/**

0 commit comments

Comments
 (0)