Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new trigger beforeLiveQueryEvent #9431

Open
codeKonami opened this issue Nov 12, 2024 · 1 comment · May be fixed by #9445
Open

Add a new trigger beforeLiveQueryEvent #9431

codeKonami opened this issue Nov 12, 2024 · 1 comment · May be fixed by #9445
Labels
bounty:$20 Bounty applies for fixing this issue (Parse Bounty Program) type:feature New feature or improvement of existing feature

Comments

@codeKonami
Copy link

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 :

parse-server/src/RestWrite.js

Lines 1630 to 1644 in 91f9aca

RestWrite.prototype.runAfterSaveTrigger = function () {
if (!this.response || !this.response.response || this.runOptions.many) {
return;
}
// Avoid doing any setup for triggers if there is no 'afterSave' trigger for this class.
const hasAfterSaveHook = triggers.triggerExists(
this.className,
triggers.Types.afterSave,
this.config.applicationId
);
const hasLiveQuery = this.config.liveQueryController.hasLiveQuery(this.className);
if (!hasAfterSaveHook && !hasLiveQuery) {
return Promise.resolve();
}

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

Copy link

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@mtrezza mtrezza added type:feature New feature or improvement of existing feature bounty:$20 Bounty applies for fixing this issue (Parse Bounty Program) labels Nov 14, 2024
@codeKonami codeKonami linked a pull request Nov 19, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty:$20 Bounty applies for fixing this issue (Parse Bounty Program) type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants