mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-07-24 18:07:34 +02:00
Logging failures to reduce the amount of network calls,
This commit is contained in:
@@ -15,6 +15,7 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
object UrlCachedPreviewer {
|
object UrlCachedPreviewer {
|
||||||
val cache = ConcurrentHashMap<String, UrlInfoItem>()
|
val cache = ConcurrentHashMap<String, UrlInfoItem>()
|
||||||
|
val failures = ConcurrentHashMap<String, Throwable>()
|
||||||
|
|
||||||
fun previewInfo(url: String, callback: IUrlPreviewCallback? = null) {
|
fun previewInfo(url: String, callback: IUrlPreviewCallback? = null) {
|
||||||
cache[url]?.let {
|
cache[url]?.let {
|
||||||
@@ -22,6 +23,11 @@ object UrlCachedPreviewer {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
failures[url]?.let {
|
||||||
|
callback?.onFailed(it)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.IO)
|
val scope = CoroutineScope(Job() + Dispatchers.IO)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
BahaUrlPreview(url, object : IUrlPreviewCallback {
|
BahaUrlPreview(url, object : IUrlPreviewCallback {
|
||||||
@@ -31,6 +37,7 @@ object UrlCachedPreviewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailed(throwable: Throwable) {
|
override fun onFailed(throwable: Throwable) {
|
||||||
|
failures.put(url, throwable)
|
||||||
callback?.onFailed(throwable)
|
callback?.onFailed(throwable)
|
||||||
}
|
}
|
||||||
}).fetchUrlPreview()
|
}).fetchUrlPreview()
|
||||||
@@ -53,8 +60,10 @@ object UrlCachedPreviewer {
|
|||||||
// Preload Images? Isn't this too heavy?
|
// Preload Images? Isn't this too heavy?
|
||||||
} else if (videoExtension.matcher(removedParamsFromUrl).matches()) {
|
} else if (videoExtension.matcher(removedParamsFromUrl).matches()) {
|
||||||
// Do nothing for now.
|
// Do nothing for now.
|
||||||
} else {
|
} else if (isValidURL(removedParamsFromUrl)) {
|
||||||
previewInfo(it)
|
previewInfo(it)
|
||||||
|
} else {
|
||||||
|
previewInfo("https://${it}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user