Skip to content

Reduce Firestore reads from survey sync and survey list - #3984

Open
rfontanarosa wants to merge 11 commits into
masterfrom
rfontanarosa/3983/reduce-firestore-reads-from-survey-sync-and-survey-list
Open

rfontanarosa wants to merge 11 commits into
masterfrom
rfontanarosa/3983/reduce-firestore-reads-from-survey-sync-and-survey-list

Conversation

@rfontanarosa

Copy link
Copy Markdown
Collaborator

closes #3983

@rfontanarosa

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors SurveysCollectionReference to use one-shot reads via flow and get().await() instead of realtime listeners, reducing Firestore read costs. It also increases the sync delay in SurveySyncService to 30 minutes to bound reads, and updates the corresponding unit tests. The review feedback recommends ensuring main-safety for these cold flows by applying .flowOn(Dispatchers.IO) to offload the CPU-intensive document parsing from the main thread.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors SurveysCollectionReference to perform one-shot reads instead of using real-time listeners for getReadable and getPublicReadable, and increases the sync delay in SurveySyncService to 30 minutes to optimize Firestore usage. The review feedback suggests offloading these database queries and mapping operations to Dispatchers.IO to avoid blocking the main thread, and adding unit tests for getPublicReadable to comply with the repository style guide.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.08%. Comparing base (bb45618) to head (b32b2c2).

Files with missing lines Patch % Lines
...mote/firebase/schema/SurveysCollectionReference.kt 70.00% 0 Missing and 6 partials ⚠️
...oundplatform/android/data/sync/SurveySyncWorker.kt 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3984      +/-   ##
============================================
+ Coverage     70.03%   70.08%   +0.04%     
- Complexity     2106     2113       +7     
============================================
  Files           441      441              
  Lines         11869    11892      +23     
  Branches       1545     1555      +10     
============================================
+ Hits           8313     8334      +21     
+ Misses         2780     2776       -4     
- Partials        776      782       +6     
Files with missing lines Coverage Δ
...undplatform/android/data/sync/SurveySyncService.kt 100.00% <100.00%> (ø)
...atform/domain/usecases/survey/SyncSurveyUseCase.kt 100.00% <100.00%> (ø)
...oundplatform/android/data/sync/SurveySyncWorker.kt 97.61% <85.71%> (-2.39%) ⬇️
...mote/firebase/schema/SurveysCollectionReference.kt 75.86% <70.00%> (+4.43%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rfontanarosa

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request refactors survey retrieval in SurveysCollectionReference from real-time listeners (snapshots()) to one-shot reads (get().await()) to reduce Firestore billing costs, and increases the sync delay in SurveySyncService to 30 minutes. Corresponding unit tests have been updated and expanded. Feedback highlights that switching to one-shot reads might introduce UI latency on slow networks and recommends caching the resulting cold flow to avoid redundant requests. Additionally, the 30-minute sync delay is noted as potentially too long, and introducing randomized jitter is suggested to prevent a 'thundering herd' problem when multiple devices sync simultaneously.

@rfontanarosa

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request optimizes survey synchronization by splitting the process into two separate workers: a quick one for the survey definition and a delayed, jittered one for the Locations of Interest (LOIs). It also replaces realtime Firestore listeners with one-shot reads using coroutines and flows to reduce read costs. The reviewer suggested removing the blocking .result.get() call on the Operation returned by enqueueUniqueWork to prevent potential UI stutters or ANRs on the main thread.

This branch is waiting to be deployed

1 waiting deployment
e2e-approval — b32b2c24 Waiting Nov 6, 2026 by rfontanarosa via instrumentation-tests / request-approval #1376
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.

Reduce Firestore reads from survey sync and survey list

1 participant