зеркало из https://github.com/nextcloud/spreed.git
Add incremental wait before trying to get messages again after a failure
This prevents overloading both the browser and the server with continuous and immediate requests when a fetch fails due to the server returning an error (for example, if the user does not have access to a room but its messages are tried to be received anyway). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Родитель
57f2581a72
Коммит
0941e2aee6
|
@ -58,6 +58,8 @@
|
|||
this.url = OC.linkToOCS('apps/spreed/api/v1/chat', 2) + this.token;
|
||||
|
||||
this.offset = 0;
|
||||
|
||||
this._waitTimeUntilRetry = 1;
|
||||
},
|
||||
|
||||
parse: function(result) {
|
||||
|
@ -128,6 +130,8 @@
|
|||
_successfulFetch: function(collection, response) {
|
||||
this.offset += response.ocs.data.length;
|
||||
|
||||
this._waitTimeUntilRetry = 1;
|
||||
|
||||
if (this.receiveMessagesAgain) {
|
||||
this.receiveMessages();
|
||||
}
|
||||
|
@ -135,7 +139,12 @@
|
|||
|
||||
_failedFetch: function() {
|
||||
if (this.receiveMessagesAgain) {
|
||||
this.receiveMessages();
|
||||
_.delay(_.bind(this.receiveMessages, this), this._waitTimeUntilRetry * 1000);
|
||||
|
||||
// Increase the wait time until retry to at most 64 seconds.
|
||||
if (this._waitTimeUntilRetry < 64) {
|
||||
this._waitTimeUntilRetry *= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче