Skip to content

[MS-1052] CoDownSync Phase 2 - Handle diffs with CommCare#1294

Merged
BurningAXE merged 2 commits into
mainfrom
MS-1052-co-down-sync-phase-2
Aug 28, 2025
Merged

[MS-1052] CoDownSync Phase 2 - Handle diffs with CommCare#1294
BurningAXE merged 2 commits into
mainfrom
MS-1052-co-down-sync-phase-2

Conversation

@BurningAXE
Copy link
Copy Markdown
Contributor

@BurningAXE BurningAXE commented Aug 3, 2025

JIRA ticket
Will be released in: 2025.3.0

Notable changes

  • Added CommCareSyncCache that tracks which cases (and their respective GUIDs) have been synced
  • Upon successful sync of a case, subsequent syncs only sync it again if its LAST_MODIFIED date is later than the last sync date
  • New cases are synced
  • Previously synced cases that are no longer present are deleted (along with their associated enrolment records)
  • To ensure the cache is updated only after enrolment record events are actually processed and not just sent for processing (which might be interrupted by an exception that cancels the worker), a new callback onEventsProcessed() is added.

Testing guidance

  • Install CommCare and log in with an user that has access to cases with biometric data
  • Configure a project with CommCare sync
  • Sync! -> Verify all cases are synced
  • Add a new case with biometric data and sync again -> Verify it's synced
  • Modify a previously synced case -> Verify it's synced again
  • Delete a previously synced case -> Verify its ER is deleted

Additional work checklist

  • Effect on other features and security has been considered
  • Design document marked as "In development" (if applicable)
  • External (Gitbook) and internal (Confluence) Documentation is up to date (or ticket created)
  • Test cases in Testiny are up to date (or ticket created)
  • Other teams notified about the changes (if applicable)

@cla-bot cla-bot Bot added the ... label Aug 3, 2025
@BurningAXE BurningAXE force-pushed the MS-1052-co-down-sync-phase-2 branch 4 times, most recently from 536942d to 719cf52 Compare August 7, 2025 16:20
@BurningAXE BurningAXE marked this pull request as ready for review August 7, 2025 16:20
@BurningAXE BurningAXE requested a review from Copilot August 7, 2025 16:21

This comment was marked as outdated.

@BurningAXE BurningAXE force-pushed the MS-1052-co-down-sync-phase-2 branch from 719cf52 to 8dc47de Compare August 18, 2025 13:40
@BurningAXE BurningAXE force-pushed the MS-1044-co-down-sync branch 4 times, most recently from e529332 to 30057b8 Compare August 18, 2025 14:56
@BurningAXE BurningAXE force-pushed the MS-1052-co-down-sync-phase-2 branch 2 times, most recently from 67ff4c4 to 28a4d0a Compare August 20, 2025 13:14
@BurningAXE BurningAXE requested review from a team, TristramN, alex-vt, alexandr-simprints, Copilot, luhmirin-s, meladRaouf and ybourgery and removed request for a team August 20, 2025 13:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements CommCare sync phase 2 functionality to handle differential syncing by tracking synced cases and their modification timestamps. The implementation introduces a caching mechanism to sync only new or modified cases while cleaning up deleted ones.

Key changes:

  • Added CommCare sync cache to track case IDs, their corresponding Simprints IDs, and last sync timestamps
  • Implemented differential sync logic that only processes cases modified after the last sync
  • Added support for generating deletion events for cases no longer present in CommCare

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
CommCareSyncCache.kt New cache implementation for tracking synced CommCare cases
CommCareSyncDao.kt Database access object for CommCare sync cache operations
CommCareSyncDatabase.kt Room database configuration for the sync cache
SyncedCaseEntity.kt Entity representing cached case data with timestamps
CommCareEventDataSource.kt Enhanced to implement differential sync logic and cache management
BaseEventDownSyncTask.kt Modified callback mechanism from actions to events
CommCareEventSyncTask.kt Simplified to delegate cache operations to data source
SimprintsEventDownSyncTask.kt Removed unused cleanup method
EventSyncModule.kt Added dependency injection for CommCare cache components
EventSyncManagerImpl.kt Added cache clearing to sync reset operations
Test files Comprehensive test coverage for new functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@BurningAXE BurningAXE force-pushed the MS-1052-co-down-sync-phase-2 branch from 28a4d0a to 405881e Compare August 20, 2025 13:48
@BurningAXE BurningAXE changed the base branch from MS-1044-co-down-sync to main August 20, 2025 13:52
@BurningAXE BurningAXE force-pushed the MS-1052-co-down-sync-phase-2 branch from 405881e to e672999 Compare August 20, 2025 14:18
val casesToParse = mutableListOf<SyncedCaseEntity>()
val caseIdsPresentInCommCare = mutableListOf<String>()
// Fetch all previously synced cases with their details (including lastSyncedTimestamp)
val previouslySyncedCasesMap = commCareSyncCache.getAllSyncedCases()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems that you only need the caseId and lastModified values, so it could be more memory efficient to use `Map<String, Long> instead. You can filter by key later when removing cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes but then you need to pass the full SyncedCaseEntity to generateEnrolmentRecordDeletionEvent() because it uses its simprintsId. So, in the end we do need the full 'cases'.

@BurningAXE BurningAXE force-pushed the MS-1052-co-down-sync-phase-2 branch from e672999 to 182e3ce Compare August 27, 2025 16:22
@sonarqubecloud
Copy link
Copy Markdown

@BurningAXE BurningAXE merged commit 14ebcba into main Aug 28, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants