Fix #7340 by correclty computing function name for push event (#7341)

* Add a failing test for issue #7340

If any delay occurs after "message.event" assignation in
LiveQueryServer._onAfterSave, the next subscription or request with a different
event might overwrite it, and by that using the wrong "push" function name.

* Remove updade of message and use res.event instead

This prevent computing function name from a
incorrect event if multiple subscriptions override
one by one the message.event.

* Update CHANGELOG.md

* Replace setTimeout by async/await expressions
This commit is contained in:
Perceval Archimbaud
2021-04-13 23:47:14 +02:00
committed by GitHub
parent 45d00cee60
commit 87dcd23b6a
4 changed files with 137 additions and 66 deletions

View File

@@ -298,7 +298,6 @@ class ParseLiveQueryServer {
} else {
return null;
}
message.event = type;
res = {
event: type,
sessionToken: client.sessionToken,
@@ -334,8 +333,7 @@ class ParseLiveQueryServer {
originalParseObject = res.original.toJSON();
originalParseObject.className = res.original.className || className;
}
const functionName =
'push' + message.event.charAt(0).toUpperCase() + message.event.slice(1);
const functionName = 'push' + res.event.charAt(0).toUpperCase() + res.event.slice(1);
if (client[functionName]) {
client[functionName](requestId, currentParseObject, originalParseObject);
}