-
Notifications
You must be signed in to change notification settings - Fork 1
Fix _logId() collision in SyncRepository with per-instance counter
#8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ class SyncRepository<T> { | |
| final SyncLogStore logStore; | ||
| final EntityIdResolver<T> idResolver; | ||
|
|
||
| int _logCounter = 0; | ||
|
|
||
| SyncRepository({ | ||
| required this.local, | ||
| required this.cloud, | ||
|
|
@@ -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
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
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 singleSyncRepositoryinstance. If multiple repositories share the sameSyncLogStore(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 alogIdNamespace/instanceIdinto the repository so IDs are unique across all writers to the same store.