From 7ffaeccc41c9540980eafc8b8b30671883345b7a Mon Sep 17 00:00:00 2001 From: Scriptbash <98601298+Scriptbash@users.noreply.github.com> Date: Mon, 30 Mar 2026 12:53:31 -0400 Subject: [PATCH] Fix creating duplicate in cloud when issn is empty --- lib/services/sync_service.dart | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/services/sync_service.dart b/lib/services/sync_service.dart index 085db192..cd783298 100644 --- a/lib/services/sync_service.dart +++ b/lib/services/sync_service.dart @@ -143,10 +143,29 @@ class SyncManager { .map((i) => i.get('issn')) .toSet(); + bool isMatch = false; // If an issn match I merge them to avoid duplicates if (localIssnSet.intersection(cloudIssnSet).isNotEmpty) { + isMatch = true; + } else if (localIssnSet.isEmpty || cloudIssnSet.isEmpty) { + String localPub = (potentialMatch['publisher'] ?? '') + .toString() + .toLowerCase() + .trim(); + String cloudPub = + r.get('publisher', '').toLowerCase().trim(); + + if (localPub.isEmpty || + cloudPub.isEmpty || + localPub.contains(cloudPub) || + cloudPub.contains(localPub)) { + isMatch = true; + } + } + + if (isMatch) { logger.info( - "Merging local journal ${potentialMatch['sync_id']} into cloud ID $cloudSyncId via ISSN match."); + "Merging local journal ${potentialMatch['sync_id']} into cloud ID $cloudSyncId."); await db.update('journals', {'sync_id': cloudSyncId}, where: 'journal_id = ?', whereArgs: [localId]);