parse-community / parse-community/parse-server

Add a new trigger `beforeLiveQueryEvent`

Open
#9,431 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type:feature
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/RestWrite.js around the referenced section and trace the liveQueryController.onAfterSave flow. Define how a beforeLiveQueryEvent trigger receives the event and how an undefined result prevents publication, then verify that objects such as status=draft are not sent to the LiveQuery server while other events still are.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.