Added Google Drive storage location
This commit is contained in:
parent
e630f2a3ec
commit
73a7c93e64
22 changed files with 1690 additions and 205 deletions
23
lib/services/merge_utils.dart
Normal file
23
lib/services/merge_utils.dart
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/// Unions [remote] and [local] by ID, keeping whichever copy of each
|
||||
/// record has the newer `updatedAt` when a record exists on both sides.
|
||||
/// This lets two devices' independent new records both survive a sync;
|
||||
/// it does not propagate deletions (see plan doc's Known limitations).
|
||||
List<T> mergeById<T>(
|
||||
List<T> remote,
|
||||
List<T> local,
|
||||
String Function(T) idOf,
|
||||
DateTime Function(T) updatedAtOf,
|
||||
) {
|
||||
final merged = <String, T>{};
|
||||
for (final item in remote) {
|
||||
merged[idOf(item)] = item;
|
||||
}
|
||||
for (final item in local) {
|
||||
final id = idOf(item);
|
||||
final existing = merged[id];
|
||||
if (existing == null || !updatedAtOf(existing).isAfter(updatedAtOf(item))) {
|
||||
merged[id] = item;
|
||||
}
|
||||
}
|
||||
return merged.values.toList();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue