getLastModified method

  1. @override
Hlc getLastModified({
  1. String? onlyNodeId,
  2. String? exceptNodeId,
})
override

Returns the last modified timestamp, optionally filtering for or against a specific node id. Useful to get "modified since" timestamps for synchronization. Returns Hlc.zero if no timestamp is found.

Implementation

@override
Hlc getLastModified({String? onlyNodeId, String? exceptNodeId}) {
  assert(onlyNodeId == null || exceptNodeId == null);

  final hlc = tables
      .map((e) => getRecords(e).entries.map((e) => e.value))
      // Flatten records into single iterable
      .fold(<Record>[], (p, e) => p..addAll(e))
      // Apply filters
      .where((e) =>
          (onlyNodeId == null && exceptNodeId == null) ||
          (onlyNodeId != null && e.hlc.nodeId == onlyNodeId) ||
          (exceptNodeId != null && e.hlc.nodeId != exceptNodeId))
      // Get only modified times
      .map((e) => e.modified)
      // Get highest time
      .fold(Hlc.zero(nodeId), (p, e) => p > e ? p : e);

  return hlc;
}