Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caching questionnaires and their SM #3461

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

aurangzaibumer
Copy link
Contributor

@aurangzaibumer aurangzaibumer commented Aug 23, 2024

IMPORTANT: Where possible all PRs must be linked to a Github issue

Fixes [link to issue]

image

Engineer Checklist

  • I have written Unit tests for any new feature(s) and edge cases for bug fixes
  • I have added any strings visible on UI components to the strings.xml file
  • I have updated the CHANGELOG.md file for any notable changes to the codebase
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the project's style guide
  • I have built and run the FHIRCore app to verify my change fixes the issue and/or does not break the app
  • I have checked that this PR does NOT introduce breaking changes that require an update to Content and/or Configs? If it does add a sample here or a link to exactly what changes need to be made to the content.

Code Reviewer Checklist

  • I have verified Unit tests have been written for any new feature(s) and edge cases
  • I have verified any strings visible on UI components are in the strings.xml file
  • I have verifed the CHANGELOG.md file has any notable changes to the codebase
  • I have verified the solution has been implemented in a configurable and generic way for reuseable components
  • I have built and run the FHIRCore app to verify the change fixes the issue and/or does not break the app

@aurangzaibumer aurangzaibumer self-assigned this Aug 23, 2024
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.

Project coverage is 27.3%. Comparing base (6fc15b0) to head (c173f82).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
...er/fhircore/engine/data/local/DefaultRepository.kt 25.0% 5 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main   #3461     +/-   ##
=========================================
+ Coverage     27.1%   27.3%   +0.2%     
- Complexity     775     782      +7     
=========================================
  Files          279     281      +2     
  Lines        14563   14551     -12     
  Branches      2608    2602      -6     
=========================================
+ Hits          3957    3985     +28     
+ Misses       10065   10023     -42     
- Partials       541     543      +2     
Flag Coverage Δ
engine 63.8% <72.7%> (+<0.1%) ⬆️
geowidget 16.0% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...egister/fhircore/engine/data/local/ContentCache.kt 100.0% <100.0%> (ø)
...ster/fhircore/engine/task/FhirCarePlanGenerator.kt 78.2% <100.0%> (+0.1%) ⬆️
...tregister/fhircore/quest/ui/login/LoginActivity.kt 5.8% <ø> (ø)
...e/quest/ui/questionnaire/QuestionnaireViewModel.kt 3.3% <ø> (+<0.1%) ⬆️
...er/fhircore/engine/data/local/DefaultRepository.kt 58.6% <25.0%> (-0.4%) ⬇️

@LZRS LZRS requested a review from ndegwamartin August 27, 2024 09:11
@aurangzaibumer aurangzaibumer marked this pull request as ready for review September 2, 2024 08:34
@ndegwamartin
Copy link
Contributor

@aurangzaibumer could we add a unit test for the ViewModel itself? You can mock anything you don't need/already tested in the Cache test if need be.

@dubdabasoduba dubdabasoduba changed the title [WIP] Caching questionnaires and their SM Caching questionnaires and their SM Sep 2, 2024
ContentCache.getResource(ResourceType.Questionnaire.name + "/" + questionnaireConfig.id),
)
Assert.assertNotNull(questionnaire)
Assert.assertEquals(questionnaireConfig.id, questionnaire?.id?.extractLogicalIdUuid())
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets add a verify assertion here to verify that the
defaultRepository.loadResource<Questionnaire>(questionnaireConfig.id) method was not called (i.e. was called zero times)

Copy link
Contributor

Choose a reason for hiding this comment

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

And we can probably split this to 2 unit tests to get better coverage for the changes in this class.

  • Test case 1 to test for when the questionnaire is Found in the cache
  • Test case 2 to test for when the questionnaire is Not Found in the cache

So basically use the:

val questionnaire =
      questionnaireViewModel.retrieveQuestionnaire(
        questionnaireConfig = questionnaireConfig,
      ) 

method as the focus of the test case and leave out the ContentCache.save invocations since those are already tested in the ContentCacheTest class

Comment on lines 655 to 661
structureMapUrl?.substringAfterLast("/")?.let { smID ->
ContentCache.getResource(ResourceType.StructureMap.name + "/" + smID)?.let {
it as StructureMap
}
?: run {
defaultRepository.loadResource<StructureMap>(smID)?.also {
ContentCache.saveResource(smID, it)
Copy link
Contributor

Choose a reason for hiding this comment

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

We can add some test cases for the Structure Map caching as well

Comment on lines 25 to 28
private val maxMemory: Int = (Runtime.getRuntime().maxMemory() / 1024).toInt()
private val cacheSize: Int = maxMemory / 8
private val cache = LruCache<String, Resource>(cacheSize)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the strategy used when this cache is full?

Copy link
Contributor

Choose a reason for hiding this comment

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

Least recently used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants