[Review] Updated the poller to process config messages before standard

This commit is contained in:
Morgan Pretty 2023-06-07 17:12:22 +10:00
parent 4a2289646e
commit d093d676f6

View File

@ -43,9 +43,6 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
private var hasStarted: Boolean = false private var hasStarted: Boolean = false
private val usedSnodes: MutableSet<Snode> = mutableSetOf() private val usedSnodes: MutableSet<Snode> = mutableSetOf()
var isCaughtUp = false var isCaughtUp = false
var configPollingJob: Job? = null
private val configDebouncer = WindowDebouncer(3000, debounceTimer)
// region Settings // region Settings
companion object { companion object {
@ -211,25 +208,8 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
return@bind Promise.ofSuccess(Unit) return@bind Promise.ofSuccess(Unit)
} else { } else {
val responseList = (rawResponses["results"] as List<RawResponse>) val responseList = (rawResponses["results"] as List<RawResponse>)
// the first response will be the personal messages
val personalResponseIndex = requestSparseArray.indexOfKey(Namespace.DEFAULT)
if (personalResponseIndex >= 0) {
responseList.getOrNull(personalResponseIndex)?.let { rawResponse ->
if (rawResponse["code"] as? Int != 200) {
Log.e("Loki", "Batch sub-request for personal messages had non-200 response code, returned code ${(rawResponse["code"] as? Int) ?: "[unknown]"}")
} else {
val body = rawResponse["body"] as? RawResponse
if (body == null) {
Log.e("Loki", "Batch sub-request for personal messages didn't contain a body")
} else {
processPersonalMessages(snode, body)
}
}
}
}
// in case we had null configs, the array won't be fully populated // in case we had null configs, the array won't be fully populated
// index of the sparse array key iterator should be the request index, with the key being the namespace // index of the sparse array key iterator should be the request index, with the key being the namespace
configDebouncer.publish {
// TODO: add in specific ordering of config namespaces for processing // TODO: add in specific ordering of config namespaces for processing
requestSparseArray.keyIterator().withIndex().forEach { (requestIndex, key) -> requestSparseArray.keyIterator().withIndex().forEach { (requestIndex, key) ->
responseList.getOrNull(requestIndex)?.let { rawResponse -> responseList.getOrNull(requestIndex)?.let { rawResponse ->
@ -254,7 +234,24 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
} }
} }
} }
// the first response will be the personal messages (we want these to be processed after config messages)
val personalResponseIndex = requestSparseArray.indexOfKey(Namespace.DEFAULT)
if (personalResponseIndex >= 0) {
responseList.getOrNull(personalResponseIndex)?.let { rawResponse ->
if (rawResponse["code"] as? Int != 200) {
Log.e("Loki", "Batch sub-request for personal messages had non-200 response code, returned code ${(rawResponse["code"] as? Int) ?: "[unknown]"}")
} else {
val body = rawResponse["body"] as? RawResponse
if (body == null) {
Log.e("Loki", "Batch sub-request for personal messages didn't contain a body")
} else {
processPersonalMessages(snode, body)
} }
}
}
}
poll(snode, deferred) poll(snode, deferred)
} }
}.fail { }.fail {