statusForPriority method

SyncPriorityStatus statusForPriority(
  1. BucketPriority priority
)

Returns information for lastSyncedAt and hasSynced information at a partial sync priority, or null if the status for that priority is unknown.

The information returned may be more generic than requested. For instance, a fully-completed sync cycle (as expressed by lastSyncedAt) necessarily includes all buckets across all priorities. So, if no further partial checkpoints have been received since that complete sync, statusForPriority may return information for that complete sync. Similarly, requesting the sync status for priority 1 may return information extracted from the lower priority 2 since each partial sync in priority 2 necessarily includes a consistent view over data in priority 1.

Implementation

SyncPriorityStatus statusForPriority(BucketPriority priority) {
  assert(priorityStatusEntries.isSortedByCompare(
      (e) => e.priority, BucketPriority.comparator));

  for (final known in priorityStatusEntries) {
    // Lower-priority buckets are synchronized after higher-priority buckets,
    // and since priorityStatusEntries is sorted we look for the first entry
    // that doesn't have a higher priority.
    if (known.priority <= priority) {
      return known;
    }
  }

  // If we have a complete sync, that necessarily includes all priorities.
  return (
    priority: priority,
    hasSynced: hasSynced,
    lastSyncedAt: lastSyncedAt
  );
}