pushDelta method

  1. @override
Future<void> pushDelta({
  1. required String collection,
  2. required String recordId,
  3. required Map<String, dynamic> delta,
  4. required int baseVersion,
  5. required DateTime timestamp,
})
override

Push delta (partial update) to backend.

Only sends changed fields instead of the entire document, reducing bandwidth by up to 98%.

Parameters:

  • collection: Collection name
  • recordId: Document ID
  • delta: Only the fields that changed
  • baseVersion: Version before this update
  • timestamp: When the update occurred

If the backend doesn't support delta sync, this should fall back to a regular push() with the full document.

Implementation

@override
Future<void> pushDelta({
  required String collection,
  required String recordId,
  required Map<String, dynamic> delta,
  required int baseVersion,
  required DateTime timestamp,
}) async {
  final key = _getKey(collection, recordId);
  final indexKey = _getIndexKey(collection);

  await command.send_object([
    'HSET',
    key,
    'data',
    jsonEncode(delta),
    'updated_at',
    timestamp.toIso8601String(),
  ]);
  await command.send_object(['HINCRBY', key, 'version', '1']);
  await command.send_object([
    'ZADD',
    indexKey,
    timestamp.millisecondsSinceEpoch.toString(),
    recordId,
  ]);
}