diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-10-24 00:15:06 +0300 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-11-03 13:28:38 +0300 |
commit | 0941e2aee6dc44baf4c520782ee5d755e252a17f (patch) | |
tree | 9fe6cbf2e531769f70ab5ac6c1ddba53ca82dcb0 /js/models | |
parent | 57f2581a7219d1682ef99109da9f38fa0f0f8c18 (diff) |
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>
Diffstat (limited to 'js/models')
-rw-r--r-- | js/models/chatmessagecollection.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/js/models/chatmessagecollection.js b/js/models/chatmessagecollection.js index 9d580434e..349d02517 100644 --- a/js/models/chatmessagecollection.js +++ b/js/models/chatmessagecollection.js @@ -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; + } } } |