Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/src/bloc_like/repository/sync_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class SyncRepository<T> {
final SyncLogStore logStore;
final EntityIdResolver<T> idResolver;

int _logCounter = 0;

Comment on lines +14 to +15

Copilot AI Feb 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_logId() now guarantees uniqueness only within a single SyncRepository instance. If multiple repositories share the same SyncLogStore (or if a store persists across app restarts and the counter resets), collisions can still happen because the ID lacks a repository/device/component discriminator. Consider including a configurable prefix (e.g., repository/device ID) or passing a logIdNamespace/instanceId into the repository so IDs are unique across all writers to the same store.

Copilot uses AI. Check for mistakes.
SyncRepository({
required this.local,
required this.cloud,
Expand Down Expand Up @@ -142,7 +144,8 @@ class SyncRepository<T> {
}

String _logId() {
_logCounter += 1;
final micros = DateTime.now().microsecondsSinceEpoch;
return 'sync_log_$micros';
return 'sync_log_${micros}_$_logCounter';
Comment on lines 146 to +149

Copilot AI Feb 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change addresses a timing-resolution collision, but there’s no deterministic test covering it (calling add() in a tight loop may not reliably reproduce the original bug on all platforms). To make this behavior testable and prevent regressions, consider injecting a time provider/clock into SyncRepository (used by _logId() and SyncLog.timestamp) so a test can force identical timestamps and assert IDs remain unique.

Copilot uses AI. Check for mistakes.
}
}