Merge pull request #5625 from overleaf/jpa-block-update-loop

[web] block a loop of failing rootDoc update requests

GitOrigin-RevId: 1388024fc125ee1e80e45a7bbbc787306cb60d1d
This commit is contained in:
Jakob Ackermann 2021-11-02 11:33:39 +01:00 committed by Copybot
parent b5998148e7
commit 8ba1803972

View file

@ -184,6 +184,7 @@ export default App.controller(
}
})
let rootDocUpdateFailed = 0
$scope.$watch('project.rootDoc_id', (rootDoc_id, oldRootDoc_id) => {
if (this.ignoreUpdates) {
return
@ -200,9 +201,25 @@ export default App.controller(
}
// otherwise only save changes, null values are allowed
if (rootDoc_id !== oldRootDoc_id) {
settings.saveProjectSettings({ rootDocId: rootDoc_id }).catch(() => {
$scope.project.rootDoc_id = oldRootDoc_id
})
settings
.saveProjectSettings({ rootDocId: rootDoc_id })
.then(() => {
rootDocUpdateFailed = 0
})
.catch(() => {
rootDocUpdateFailed++
// Let the login redirect run (if any) and reset afterwards.
setTimeout(() => {
if (rootDocUpdateFailed > 10) {
// We are in a loop of failing updates. Stop now.
this.ignoreUpdates = true
}
$scope.$apply(() => {
$scope.project.rootDoc_id = oldRootDoc_id
})
this.ignoreUpdates = false
})
})
}
})