Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][contacts] clamp sync retries to server limit

Neeraj Guptae7a1dc3c7063
diff --git a/mobile/packages/contacts/lib/src/service/contacts_service.dart b/mobile/packages/contacts/lib/src/service/contacts_service.dart
index b15decfda8..2dedd21649 100644
--- a/mobile/packages/contacts/lib/src/service/contacts_service.dart
+++ b/mobile/packages/contacts/lib/src/service/contacts_service.dart
@@ -10,8 +10,8 @@ import 'package:logging/logging.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ContactsService {
- static const _syncLimit = 5000;
- static const _maxSyncLimit = 50000;
+ static const _serverMaxSyncLimit = 5000;
+ static const _syncLimit = _serverMaxSyncLimit;
ContactsService({
required SharedPreferences preferences,
@@ -84,12 +84,13 @@ class ContactsService {
if (sinceTime == previousSinceTime &&
previousPageIds != null &&
_sameIds(previousPageIds, pageIds)) {
- if (limit >= _maxSyncLimit) {
+ if (limit >= _serverMaxSyncLimit) {
throw StateError(
- 'Contacts sync pagination stalled at updatedAt ${diff.last.updatedAt}',
+ 'Contacts sync pagination stalled at updatedAt '
+ '${diff.last.updatedAt} within server limit $_serverMaxSyncLimit',
);
}
- limit = min(limit * 2, _maxSyncLimit);
+ limit = min(limit * 2, _serverMaxSyncLimit);
continue;
}
await _database.upsertContacts(diff);
diff --git a/mobile/packages/contacts/test/contacts_service_test.dart b/mobile/packages/contacts/test/contacts_service_test.dart
index bae1aa84d9..ba147f2ccd 100644
--- a/mobile/packages/contacts/test/contacts_service_test.dart
+++ b/mobile/packages/contacts/test/contacts_service_test.dart
@@ -283,8 +283,7 @@ void main() {
},
);
- test('sync increases overlap page size to avoid skipping equal timestamps',
- () async {
+ test('sync clamps overlap retries to the server page cap', () async {
final firstPage = <ContactRecord>[
for (var i = 0; i < 5000; i++)
ContactRecord(
@@ -298,16 +297,6 @@ void main() {
updatedAt: 20,
),
];
- const overflow = ContactRecord(
- id: 'ct_overflow',
- contactUserId: 6002,
- email: '[email protected]',
- data: ContactData(contactUserId: 6002, name: 'Overflow'),
- profilePictureAttachmentId: null,
- isDeleted: false,
- createdAt: 10,
- updatedAt: 20,
- );
rustApi.ctx.diffHandler = (sinceTime, limit) async {
if (sinceTime == 0) {
return firstPage;
@@ -315,9 +304,6 @@ void main() {
if (sinceTime == 19 && limit == 5000) {
return firstPage;
}
- if (sinceTime == 19 && limit == 10000) {
- return [...firstPage, overflow];
- }
return const [];
};
@@ -330,19 +316,14 @@ void main() {
),
);
- final synced = await service.sync();
+ await expectLater(service.sync(), throwsStateError);
- expect(
- synced.any((contact) => contact.id == 'ct_overflow'),
- isTrue,
- );
expect(rustApi.ctx.diffSinceTimes.first, 0);
expect(rustApi.ctx.diffSinceTimes.skip(1), everyElement(19));
expect(rustApi.ctx.diffLimits.first, 5000);
expect(rustApi.ctx.diffLimits.where((limit) => limit == 5000), isNotEmpty);
- expect(rustApi.ctx.diffLimits, contains(10000));
- expect((await service.getContact('ct_overflow'))?.data?.name, 'Overflow');
- expect(synced.where((contact) => contact.id == 'ct_0'), hasLength(1));
+ expect(rustApi.ctx.diffLimits.every((limit) => limit <= 5000), isTrue);
+ expect((await service.getContact('ct_overflow'))?.data?.name, isNull);
});
}