parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.94k stars 4.78k forks source link

Add a new trigger `beforeLiveQueryEvent` #9431

Open codeKonami opened 1 day ago

codeKonami commented 1 day ago

New Feature / Enhancement Checklist

Current Limitation

As of today, as soon as you declare a className in the new ParseServer({ liveQuery: { classNames: [...] }}) all events are systematically published through the PubSubAdapter (Redis for example). Then the LiveQuery server receives the event and depending on the subscriptions it evaluates which Livequery clients should receive a message through WebSocket.

We encountered a limitation because sometimes we would like to limit the events sent to the LiveQuery server since it can consume a lot of CPU to evaluate all the subscriptions.

Feature / Enhancement Description

The idea would be to implement a "beforeLiveQueryEvent" that would prevent a publish depending on some business logic.

I think the main location of the code would be in this section : https://github.com/parse-community/parse-server/blob/91f9aca25bc6212ae27aac7af328ee1f19f058c8/src/RestWrite.js#L1630-L1644

If a beforeLiveQueryEvent trigger is defined that the className has LiveQuery then you would pass in the function, if the function return undefined you would prevent the liveQueryController.onAfterSave

Example Use Case

For example, we don't want the LiveQuery server to treat in real time some object that would have a status === 'draft' because our business logic don't depend on it even though a lot of object are created with this status.

Alternatives / Workarounds

There is none at the moment since you activate globally to the className.

3rd Party References

No

parse-github-assistant[bot] commented 1 day ago

Thanks for opening this issue!