Skip to content

Commit

Permalink
fix: 画像のキャッシュをしないようにした。
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Jun 26, 2023
1 parent b8d4842 commit cc6f26f
Showing 1 changed file with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import android.net.Uri
import dagger.hilt.android.qualifiers.ApplicationContext
import io.objectbox.BoxStore
import io.objectbox.kotlin.awaitCallInTx
import io.objectbox.kotlin.inValues
import io.objectbox.query.QueryBuilder
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -35,7 +34,7 @@ class ImageCacheRepositoryImpl @Inject constructor(

companion object {
const val cacheDir = "milktea_image_caches"
val cacheExpireDuration = 7.days
// val cacheExpireDuration = 7.days
val cacheIgnoreUpdateDuration = 3.days
}

Expand Down Expand Up @@ -77,21 +76,22 @@ class ImageCacheRepositoryImpl @Inject constructor(
}

override suspend fun findBySourceUrl(url: String): ImageCache? {
return withContext(coroutineDispatcher) {
val now = Clock.System.now()
val record = imageCacheStore.query().equal(
ImageCacheRecord_.sourceUrl,
url,
QueryBuilder.StringOrder.CASE_SENSITIVE
).build().findFirst()
val model = record?.toModel()
if (model != null && now - model.cachedAt > cacheExpireDuration) {
imageCacheStore.remove(record)
null
} else {
model
}
}
// return withContext(coroutineDispatcher) {
// val now = Clock.System.now()
// val record = imageCacheStore.query().equal(
// ImageCacheRecord_.sourceUrl,
// url,
// QueryBuilder.StringOrder.CASE_SENSITIVE
// ).build().findFirst()
// val model = record?.toModel()
// if (model != null && now - model.cachedAt > cacheExpireDuration) {
// imageCacheStore.remove(record)
// null
// } else {
// model
// }
// }
return null
}

override suspend fun deleteExpiredCaches() {
Expand All @@ -112,22 +112,23 @@ class ImageCacheRepositoryImpl @Inject constructor(
}

override suspend fun findBySourceUrls(urls: List<String>): List<ImageCache> {
return withContext(coroutineDispatcher) {
val now = Clock.System.now()
val records = imageCacheStore.query().inValues(
ImageCacheRecord_.sourceUrl,
urls.toTypedArray(),
QueryBuilder.StringOrder.CASE_SENSITIVE
).build().find()
records.mapNotNull { record ->
val model = record.toModel()
if (now - model.cachedAt > cacheExpireDuration) {
null
} else {
model
}
}
}
// return withContext(coroutineDispatcher) {
// val now = Clock.System.now()
// val records = imageCacheStore.query().inValues(
// ImageCacheRecord_.sourceUrl,
// urls.toTypedArray(),
// QueryBuilder.StringOrder.CASE_SENSITIVE
// ).build().find()
// records.mapNotNull { record ->
// val model = record.toModel()
// if (now - model.cachedAt > cacheExpireDuration) {
// null
// } else {
// model
// }
// }
// }
return emptyList()
}

private suspend fun upInsert(cache: ImageCache) {
Expand Down

0 comments on commit cc6f26f

Please sign in to comment.