Skip to content

MS-1148 Sync state use case simplification spike#1495

Merged
luhmirin-s merged 4 commits into
mainfrom
feature/MS-1148-sync-simplification
Dec 9, 2025
Merged

MS-1148 Sync state use case simplification spike#1495
luhmirin-s merged 4 commits into
mainfrom
feature/MS-1148-sync-simplification

Conversation

@luhmirin-s
Copy link
Copy Markdown
Contributor

JIRA ticket

Unfortunately, I was unable to find a way to implement any meaningful changes on a larger scale. The business logic part does exactly what it should, and while it is a bit verbose, there are a lot of cases to cover. Additional simplification may arise from architectural changes in the data layer/sync management, but this remains to be seen.

Notable changes

  • Mostly cosmetic changes in the code to slightly improve readability.
  • Extracted several config manager components out of the main use case body.
  • Removed a couple of minor redundant parts.

Testing guidance

  • Run usual sync test cases.

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)

@luhmirin-s luhmirin-s requested review from a team, BurningAXE, TristramN, alex-vt, alexandr-simprints, meladRaouf and ybourgery and removed request for a team December 8, 2025 14:35
@cla-bot cla-bot Bot added the ... label Dec 8, 2025
@luhmirin-s luhmirin-s force-pushed the feature/MS-1148-sync-simplification branch from 7391149 to bdd4b1c Compare December 8, 2025 14:53
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 refactors the sync state management code to improve readability and maintainability. The main changes involve extracting configuration observation logic into a dedicated use case, simplifying the Ticker component, removing unused code, and streamlining test setup.

Key Changes

  • Extracted ObserveConfigurationChangesUseCase: Configuration management logic (project state, module counts, tokenization) has been moved into a separate use case, reducing complexity in ObserveSyncInfoUseCase
  • Simplified Ticker component: Converted from an interface-implementation pattern to a concrete class with a more flexible API that accepts any Duration instead of being hardcoded to one minute
  • Removed unused code: Eliminated the combine9 Flow extension and associated tests, along with redundant module tokenization tests

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
infra/core/src/test/java/com/simprints/core/tools/time/TickerTest.kt Updated tests to work with new Ticker concrete class and observeTicks(Duration) method
infra/core/src/test/java/com/simprints/core/tools/extentions/FlowExtTest.kt Removed test for unused combine9 function
infra/core/src/test/java/com/simprints/core/lifecycle/AppForegroundStateTrackerTest.kt Updated test to inject dispatcher dependency
infra/core/src/main/java/com/simprints/core/tools/time/TickerImpl.kt Removed implementation class as Ticker is now a concrete class
infra/core/src/main/java/com/simprints/core/tools/time/Ticker.kt Converted from interface to concrete class with flexible observeTicks(Duration) method
infra/core/src/main/java/com/simprints/core/tools/extentions/Flow.ext.kt Removed unused combine9 extension function
infra/core/src/main/java/com/simprints/core/lifecycle/AppForegroundStateTracker.kt Added main dispatcher injection and flowOn operator for thread safety
infra/core/src/main/java/com/simprints/core/CoreModule.kt Removed provideTicker() method as Ticker now uses constructor injection
feature/dashboard/src/test/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCaseTest.kt Extensive refactoring to use new ObserveConfigurationChangesUseCase and helper methods for test setup
feature/dashboard/src/test/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveConfigurationChangesUseCaseTest.kt New test file for the extracted configuration observation use case
feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCase.kt Refactored to use extracted configuration use case, simplified progress calculation, improved code organization
feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveConfigurationChangesUseCase.kt New use case that encapsulates configuration observation, module counting, and tokenization logic
feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/modulecount/ModuleCountViewHolder.kt Updated to display localized "Total Records" text for the first item instead of an empty string
feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/SyncInfoFragment.kt Simplified adapter submission by directly using ModuleCount instead of converting from SyncInfoModuleCount
feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/SyncInfo.kt Changed visibility to internal, removed SyncInfoModuleCount in favor of ModuleCount, simplified data structures
Comments suppressed due to low confidence (1)

infra/core/src/test/java/com/simprints/core/tools/time/TickerTest.kt:3

  • Avoid using wildcard imports (import com.google.common.truth.Truth.*). Use explicit imports instead (e.g., import com.google.common.truth.Truth.assertThat) to improve code readability and avoid potential naming conflicts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Showing only event sync progress
eventSyncState.isSyncInProgress() && totalEvents > 0 -> eventProgressProportion

// Sync haven't started
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

Grammar error in comment: "Sync haven't started" should be "Sync hasn't started".

Suggested change
// Sync haven't started
// Sync hasn't started

Copilot uses AI. Check for mistakes.
return@combine syncInfo
}.onRecordSyncComplete { delay(timeMillis = SYNC_COMPLETION_HOLD_MILLIS) }
.onImageSyncComplete { delay(timeMillis = SYNC_COMPLETION_HOLD_MILLIS) }
.flowOn(dispatcher) // upstream flows does a lot of computation
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

The comment should be updated to use correct grammar: "upstream flows does" should be "upstream flows do".

Suggested change
.flowOn(dispatcher) // upstream flows does a lot of computation
.flowOn(dispatcher) // upstream flows do a lot of computation

Copilot uses AI. Check for mistakes.
@luhmirin-s luhmirin-s force-pushed the feature/MS-1148-sync-simplification branch from bdd4b1c to bbef1ca Compare December 9, 2025 07:41
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 9, 2025

@luhmirin-s luhmirin-s merged commit 0c16335 into main Dec 9, 2025
13 checks passed
@luhmirin-s luhmirin-s deleted the feature/MS-1148-sync-simplification branch December 9, 2025 08:16
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.

3 participants