Skip to content

Only prime cache, if it is available#1538

Merged
MartinRiese merged 3 commits into
masterfrom
riese/no_cache_no_prime
May 20, 2026
Merged

Only prime cache, if it is available#1538
MartinRiese merged 3 commits into
masterfrom
riese/no_cache_no_prime

Conversation

@MartinRiese

@MartinRiese MartinRiese commented May 15, 2026

Copy link
Copy Markdown
Contributor

Product Description

Add a check in the cache priming code. Only do the priming, if there is a cache set.

Technical Summary

Safety Assurance

Safety story

Deploy to staging and test variations:

  • Web apps:
    • clickable icon ✅
    • sort defined, not defined ✅
  • mobile app:
    • sort works for enum field
    • sort works for other fields.

Automated test coverage

Added a test to check for future regressions which doubles as check on the fix.

QA Plan

Special deploy instructions

  • This PR can be deployed after merge with no further considerations.

Rollback instructions

  • This PR can be reverted after deploy with no further considerations.

Review

  • The set of people pinged as reviewers is appropriate for the level of risk of the change.

Summary by CodeRabbit

  • Bug Fixes
    • Optimized entity data computation to conditionally process legacy data only when cache storage is available, reducing unnecessary processing and improving performance during data loading operations.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5adf15df-da1c-4ea7-a697-00884fc8337c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The setUnCachedDataOld method now guards the legacy sort-field caching loop with a null check on mEntityCache. When the cache is absent, the entire loop including iteration, cancellation checks, and progress updates is skipped.

Changes

Cache Guard in Sort Field Computation

Layer / File(s) Summary
Cache null-check guard on sort-field loop
src/main/java/org/commcare/cases/entity/AsyncNodeEntityFactory.java
The setUnCachedDataOld method now checks mEntityCache != null before computing legacy sort fields; when the cache is absent, the sort-field calculation loop and all associated iteration logic is skipped.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A rabbit hops to guard the cache,
With null-checks swift and lightning-flash,
When absent, loops need not dash,
Efficiency blooms in compact stash! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Only prime cache, if it is available' directly describes the main change: the method now only primes/computes legacy uncached data when the cache is available (non-null).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch riese/no_cache_no_prime

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

if (isCancelled) return;
AsyncEntity e = (AsyncEntity)entities.get(i);
for (int col = 0; col < e.getNumFields(); ++col) {
if (mEntityCache != null) {

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.

Not sure if we would want put this behind a feature flag for now.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks like commcare-core doesn't have access to feature flags, is that right? We could pass through a boolean if we needed to - might be nice to easily toggle on and off for performance testing, but coordinating across three repos is tedious, and Shubham seemed optimistic about this change, so maybe not worth the effort. Dunno, I could go either way.

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.

yeah I am quite confident for this to be rolloed out without a feature flag.

Verifies that prepareEntities does not call getSortField during the
cache priming loop when no EntityStorageCache is present, which is
always the case in formplayer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MartinRiese
MartinRiese marked this pull request as ready for review May 18, 2026 15:12
@MartinRiese

Copy link
Copy Markdown
Contributor Author

@shubham1g5 Do you have a suggestion how to test the mobile app for regressions (making sure sort works as intended)?

@shubham1g5

Copy link
Copy Markdown
Contributor

@MartinRiese I don't think there is a need to do, the cache is always not-null for mobile when we use AsyncNodeEntityFactory so that change is essentially a no-op for mobile.

shubham1g5
shubham1g5 previously approved these changes May 19, 2026
import static org.junit.Assert.assertEquals;

/**
* Regression test for USH-6551: sort field expressions must not be evaluated during the cache

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.

Curious if it's a common practice on USS to add Jira ticket # in code comments, we have refrained from doing so on mobile team in past as the code is open source and putting these refrences make it cryptic for anyone external looking into the code.

@esoergel esoergel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

approving last commit

@MartinRiese
MartinRiese merged commit 130df00 into master May 20, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants