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.