feat: Add sync_at property for summary_data documents - #266
Conversation
📝 WalkthroughWalkthroughHandler initialization is refactored to accept ChangesServer-confirmed sync stamping via metadata listeners
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java (2)
350-365: ⚡ Quick winConsider logging listener errors for observability.
When
error != null, the listener silently returns without logging. This could make debugging difficult if listeners fail unexpectedly (e.g., permission errors, network issues).♻️ Suggested improvement
holder[0] = docRef.addSnapshotListener(MetadataChanges.INCLUDE, (snapshot, error) -> { - if (snapshot == null || error != null) return; + if (error != null) { + Log.w(TAG, "Sync listener error for docId=" + docId, error); + return; + } + if (snapshot == null) return; if (!snapshot.getMetadata().hasPendingWrites() && !snapshot.getMetadata().isFromCache()) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java` around lines 350 - 365, The snapshot listener currently returns silently when error != null; update the lambda passed to docRef.addSnapshotListener (the ListenerRegistration holder callback in DefaultAppEventPayloadHandler) to log the error for observability—use Log.e(TAG, "Snapshot listener error for docId=" + docId, error) (or similar) before returning, and ensure you still guard for snapshot == null; also keep existing removal of the listener and syncListeners logic unchanged.
31-37: ⚡ Quick winConsider adding listener cleanup to prevent potential memory leaks.
The
syncListenersmap holds activeListenerRegistrationinstances, but there's no method to clean them up when the handler is no longer needed (e.g., when theWebAppactivity is destroyed). If the device remains offline and listeners never fire, they could leak.Consider adding a
cleanup()method that unregisters all active listeners and clearing the map, then calling it fromWebApp.onDestroy().♻️ Suggested cleanup method
public void cleanup() { for (ListenerRegistration registration : syncListeners.values()) { if (registration != null) { registration.remove(); } } syncListeners.clear(); Log.d(TAG, "Cleaned up " + syncListeners.size() + " sync listeners"); }Then in
WebApp.java, store a reference to the handler and call cleanup inonDestroy().🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java` around lines 31 - 37, The syncListeners map holds ListenerRegistration instances but lacks teardown, so add a public cleanup() method on DefaultAppEventPayloadHandler that iterates over syncListeners.values(), calls remove() on each non-null ListenerRegistration, clears the map, and logs the number cleaned; then ensure the WebApp that creates/holds the DefaultAppEventPayloadHandler instance calls handler.cleanup() from its onDestroy() so listeners are unregistered and memory leaks avoided.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@app/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java`:
- Around line 350-365: The snapshot listener currently returns silently when
error != null; update the lambda passed to docRef.addSnapshotListener (the
ListenerRegistration holder callback in DefaultAppEventPayloadHandler) to log
the error for observability—use Log.e(TAG, "Snapshot listener error for docId="
+ docId, error) (or similar) before returning, and ensure you still guard for
snapshot == null; also keep existing removal of the listener and syncListeners
logic unchanged.
- Around line 31-37: The syncListeners map holds ListenerRegistration instances
but lacks teardown, so add a public cleanup() method on
DefaultAppEventPayloadHandler that iterates over syncListeners.values(), calls
remove() on each non-null ListenerRegistration, clears the map, and logs the
number cleaned; then ensure the WebApp that creates/holds the
DefaultAppEventPayloadHandler instance calls handler.cleanup() from its
onDestroy() so listeners are unregistered and memory leaks avoided.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3d458729-5f2f-4c99-b34c-c9af19088b4e
📒 Files selected for processing (2)
app/src/main/java/org/curiouslearning/container/WebApp.javaapp/src/main/java/org/curiouslearning/container/core/subapp/handler/DefaultAppEventPayloadHandler.java
Changes
How to test
Notes:
You will need to add android sdk to your environment variables when working on windows.
Ref: MR-86
Summary by CodeRabbit
Release Notes
New Features
Refactor