-
Notifications
You must be signed in to change notification settings - Fork 640
[realppl 5] serverTimestamp and integration tests #7353
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
base: wuandy/RealPpl_4
Are you sure you want to change the base?
Conversation
Firebase AI Mock Responses Check
|
Generated by 🚫 Danger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @wu-hui, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the Firestore client library by introducing a robust real-time data processing pipeline. It allows developers to define complex data transformations and aggregations that execute continuously, providing live updates as underlying data changes. The changes also expand the available expression functions for more powerful data manipulation and refine how server-generated timestamps are handled, ensuring greater control and accuracy in real-time applications.
Highlights
- Realtime Pipeline Enhancements: Introduced a new
RealtimePipeline
API with support for real-time snapshot listeners and Kotlin Flows, enabling continuous data updates based on defined pipeline stages. - Advanced Expression Functions: Added a suite of new expression functions, including mathematical operations (absolute value, exponentiation, logarithms, square root, rounding, ceiling, floor) and string manipulations (substring), significantly expanding the query capabilities within pipelines.
- Server Timestamp Behavior Control: Implemented explicit control over server timestamp behavior (estimate, previous, none) within
RealtimePipeline
snapshots, providing more flexibility in how timestamp fields are represented in client-side data. - Improved Query-to-Pipeline Conversion: Refined the conversion of traditional Firestore queries into pipeline stages, including a new requirement for
limitToLast()
queries to specify anorderBy()
clause for predictable results.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
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 introduces a significant new feature: Realtime Pipelines. This allows for listening to live updates on pipeline queries. The changes are extensive, touching API definitions, core logic, evaluation engines, and adding a large suite of integration tests.
The implementation looks solid. Key points:
- The new
RealtimePipeline
API is well-designed, with support for snapshot listeners and coroutine Flows. - Server timestamp handling (
estimate
,previous
,none
) is correctly implemented in the evaluation logic, plumbed through newRealtimePipelineOptions
. - The expression engine has been expanded with many new mathematical and string functions, and their evaluation logic correctly handles edge cases like
Infinity
andNaN
. - Existing tests have been improved for determinism by adding explicit sorting, and several test-only bugs have been fixed.
- The new integration tests for
RealtimePipeline
are comprehensive and cover a wide range of scenarios. - Code has been refactored for better organization, such as moving
RealtimePipeline
classes to a new file and centralizingchangesFromSnapshot
logic.
I have one suggestion for improving robustness in RealtimePipeline.kt
.
fun addSnapshotListener( | ||
executor: Executor, | ||
options: RealtimePipelineOptions, | ||
listener: EventListener<RealtimePipelineSnapshot> | ||
): ListenerRegistration { | ||
val userListener = | ||
EventListener<ViewSnapshot> { snapshot, error -> | ||
val realtimeSnapshot = snapshot?.let { RealtimePipelineSnapshot(it, firestore!!, options) } | ||
listener.onEvent(realtimeSnapshot, error) | ||
} | ||
|
||
val asyncListener = AsyncEventListener(executor, userListener) | ||
|
||
return firestore!!.callClient { client -> | ||
val listener: QueryListener = | ||
client!!.listen( | ||
QueryOrPipeline.PipelineWrapper(this), | ||
options.toListenOptions(), | ||
asyncListener | ||
) | ||
ListenerRegistration { | ||
asyncListener.mute() | ||
client!!.stopListening(listener) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The firestore
property can be null for RealtimePipeline
instances that are deserialized from the cache, and the client
in callClient
can also be null. Using the non-null assertion operator (!!
) could lead to a NullPointerException
if this method is ever called on such an instance or if the client is not available.
While the current code flow seems to prevent this, adding explicit checks would make the code more robust and clearly state the preconditions for this method.
fun addSnapshotListener(
executor: Executor,
options: RealtimePipelineOptions,
listener: EventListener<RealtimePipelineSnapshot>
): ListenerRegistration {
checkNotNull(firestore) {
"This RealtimePipeline instance cannot be used to listen to snapshots. It may have been deserialized from persistence."
}
val userListener =
EventListener<ViewSnapshot> { snapshot, error ->
val realtimeSnapshot = snapshot?.let { RealtimePipelineSnapshot(it, firestore, options) }
listener.onEvent(realtimeSnapshot, error)
}
val asyncListener = AsyncEventListener(executor, userListener)
return firestore.callClient { client ->
checkNotNull(client) { "FirestoreClient should not be null." }
val listener: QueryListener =
client.listen(
QueryOrPipeline.PipelineWrapper(this),
options.toListenOptions(),
asyncListener
)
ListenerRegistration {
asyncListener.mute()
client.stopListening(listener)
}
}
}
Coverage Report 1Affected Products
Test Logs |
Size Report 1Affected Products
Test Logs |
3187cd1
to
748f6cf
Compare
d013c6d
to
164fbde
Compare
164fbde
to
2110f36
Compare
No description provided.