You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue proposes a refactoring of the purge function within the engine module for improved code readability and maintainability. The current implementation checks for resource presence, local changes, and force purge flag within nested conditional statements, potentially leading to less readable and maintainable code.
Suggested Changes:
The proposed refactor aims to achieve the same functionality with improved clarity by:
Combined check for local changes and force purge: Combine the checks for local changes (localChanges.isNotEmpty()) and the forcePurge flag within a single condition.
Concise comments: Add concise comments to explain the logic behind each step.
Reduced redundancy:
Benefits:
Improved code readability by separating concerns and using clear logic flow.
Enhanced maintainability by simplifying conditional checks and reducing nesting.
Potentially clearer code for future developers working on this functionality.
Attached Code Snippets:
Include the current and proposed code snippets within the issue description for easy reference:
Current Code:
overridesuspendfunpurge(type:ResourceType, ids:Set<String>, forcePurge:Boolean) {
db.withTransaction {
ids.forEach { id ->// To check resource is present in DB else throw ResourceNotFoundException()
selectEntity(type, id)
val localChangeEntityList = localChangeDao.getLocalChanges(type, id)
// If local change is not available simply delete resourceif (localChangeEntityList.isEmpty()) {
resourceDao.deleteResource(resourceId = id, resourceType = type)
} else {
// local change is available with FORCE_PURGE the delete resource and discard changes from// localChangeEntity tableif (forcePurge) {
resourceDao.deleteResource(resourceId = id, resourceType = type)
localChangeDao.discardLocalChanges(
token =LocalChangeToken(localChangeEntityList.map { it.id }),
)
} else {
// local change is available but FORCE_PURGE = false then throw exceptionthrowIllegalStateException(
"Resource with type $type and id $id has local changes, either sync with server or FORCE_PURGE required",
)
}
}
}
}
}
Proposed Code:
overridesuspendfunpurge(type:ResourceType, ids:Set<String>, forcePurge:Boolean) {
db.withTransaction {
ids.forEach { id ->// 1. Verify resource presence:
selectEntity(type, id)
// 2. Check for local changes and handle accordingly:val localChanges = localChangeDao.getLocalChanges(type, id)
if (localChanges.isNotEmpty() &&!forcePurge) {
throwIllegalStateException(
"Resource with type $type and id $id has local changes, either sync with server or FORCE_PURGE required"
)
}
// 3. Delete resource and discard local changes (if applicable):
resourceDao.deleteResource(id, type)
if (localChanges.isNotEmpty()) {
localChangeDao.discardLocalChanges(id, type)
}
}
}
}
This approach provides a clear and concise issue description for the Android FHIR repository, promoting collaboration and potential code improvement.
Would you like to work on the issue?
Yes 🚀
The text was updated successfully, but these errors were encountered:
itstanany
added a commit
to itstanany/android-fhir
that referenced
this issue
Apr 28, 2024
Describe the Issue
This issue proposes a refactoring of the
purge
function within the engine module for improved code readability and maintainability. The current implementation checks for resource presence, local changes, and force purge flag within nested conditional statements, potentially leading to less readable and maintainable code.Suggested Changes:
The proposed refactor aims to achieve the same functionality with improved clarity by:
localChanges.isNotEmpty()
) and theforcePurge
flag within a single condition.Benefits:
Attached Code Snippets:
Include the current and proposed code snippets within the issue description for easy reference:
Current Code:
Proposed Code:
This approach provides a clear and concise issue description for the Android FHIR repository, promoting collaboration and potential code improvement.
Would you like to work on the issue?
Yes 🚀
The text was updated successfully, but these errors were encountered: