parse-community / parse-community/parse-server
Persistent live queries, surviving to offline periods
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
Current Limitation
To ensure data remains synchronized on my client, I must perform several queries and subscribe to live queries whenever the app returns online after being offline even for a short period.
Feature / Enhancement Description
I would like to implement persistent live queries that survive periods of offline operation. When the app comes back online, the server should restore existing subscriptions and push all the events that occurred during the offline period to the client.
Example Use Case
// Initialize the LiveQuery client
const client = new Parse.LiveQueryClient({ ... });
// Open the connection
client.open();
// Create a query for the Books class
const BooksQuery = new Parse.Query('Books');
// Define persistent subscription options
const BooksSubscriptionOptions = {
persistent: true, // Enable persistence for this subscription
persistentTTL: 3600, // Time to live in seconds (1 hour)
persistentKey: "ALL_BOOKS" // Unique identifier for this subscription
};
// Subscribe to the query with persistence options
// If subscription was previously initiated by this device, with same persistentKey, and still within TTL, restore it and trigger relevant events heppened during offline period.
const BooksSubscription = client.subscribe(BooksQuery, BooksSubscriptionOptions);
BooksSubscription.on('create', myLocalStorage.addBook);
Alternatives / Workarounds
Currently, I need to perform a query.find() operation to fetch all books since my last connection:
// When coming back online
const lastConnectionTime = getLastConnectionTimestamp();
const BooksQuery = new Parse.Query('Books');
const subscription = client.subscribe(BooksQuery);
BooksQuery.greaterThan('updatedAt', lastConnectionTime);
BooksQuery.find().then(books => {
books.forEach(book => myLocalStorage.updateBook(book));
});
Imagine having Books, Authors, Categories, Tags, Orders, FavoriteBooks, etc... This approach is inefficient as it requires a REST call for each class.
3rd Party References
Firebase Realtime Database and Realm provide similar offline persistence capabilities:
- Firebase automatically synchronizes local changes with the server when connectivity is restored
- MongoDB Realm Sync provides seamless offline-to-online synchronization
Implementing this feature would bring Parse Platform more in line with these competing solutions.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Parse.LiveQueryClient initialization and client.subscribe(options) entry points, then trace how the server currently creates and resumes LiveQuery subscriptions. Define the persistence key, TTL, and offline event replay behavior, and verify that reconnecting within the TTL restores the subscription while expiry does not.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- backend-api-design, distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100