Skip to content

dataconnect(chore): add last_update_sequence_number to cache db#8226

Merged
dconeybe merged 5 commits into
mainfrom
dconeybe/RealtimeCacheUpdate2
May 28, 2026
Merged

dataconnect(chore): add last_update_sequence_number to cache db#8226
dconeybe merged 5 commits into
mainfrom
dconeybe/RealtimeCacheUpdate2

Conversation

@dconeybe
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe commented May 28, 2026

This pull request introduces a new last_update_sequence_number column to the Data Connect SQLite cache database for queries and entities. This sequence number tracks the order of cache updates and will be used by subsequent work to avoid publishing duplicate query results from cache in realtime query subscriptions.

Highlights

  • Monotonic Sequence Tracking: Configured DataConnectCacheDatabase to generate monotonically increasing sequence numbers using a sequence helper table, assign them to queries and entities during update transactions, and report the maximum sequence number across a query and all of its referenced entities upon retrieval.
  • Incremental Database Schema Migrator: Upgraded the cache database schema to version 1.1.0 and structured the schema migrator to perform incremental multi-step migrations, starting with database creation at 1.0.0 and applying the migration to 1.1.0 which adds the last_update_sequence_number columns.
  • Lexicographical Byte Array Ordering: Conformed ImmutableByteArray to the Comparable interface, supported by a backport of signed lexicographical byte array comparison (contentCompareTo) to ensure compatibility with Android versions below API level 33.
  • Comprehensive Integration and Unit Tests: Added regression tests for database migration and verification of database state, along with thorough testing of correct sequence number calculation and stable byte array sorting.
Changelog
  • DataConnectCacheDatabase.kt
    • Added last_update_sequence_number tracking logic, including the SqliteSequenceNumber inline value class, sequence number generation helper, and maximum last update sequence number computation during query rehydration.
  • DataConnectCacheDatabaseMigrator.kt
    • Upgraded the database schema version to 1.1.0, introduced an incremental migration runner loop, and implemented step migration from 1.0.0 to 1.1.0 to alter queries and entities tables.
  • ByteArrayUtils.kt
    • Created a utility file that backports signed lexicographical byte array comparison (contentCompareTo) for Android devices running on API levels below 33.
  • ImmutableByteArray.kt
    • Conformed ImmutableByteArray to the Comparable<ImmutableByteArray> interface, utilizing the new contentCompareTo logic to achieve a stable cross-process sort order.
  • DataConnectCacheDatabaseMigratorUnitTest.kt
    • Added integration tests verifying that existing data is preserved during progressive 1.0.0 to 1.1.0 migrations, and that proper exceptions are thrown when the database version or application ID is unrecognized.
  • DataConnectCacheDatabaseUnitTest.kt
    • Added unit tests verifying proper sequence number updates during query insertion and verifying sequence number retrieval logic, including edge cases with null database values.
  • ImmutableByteArrayUnitTest.kt
    • Added property and unit tests for the newly introduced comparison behaviors of ImmutableByteArray, covering identical arrays, prefixes, and different array lengths.
  • CartesianProduct.kt
    • Added a utility function to compute the cartesian product of two iterables to support unit testing.
  • TestValueGenerator.kt
    • Added a utility class to facilitate deterministic test sample generation from Kotest arbitrary data generators (Arb) outside of standard property-based tests.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 counterproductive. 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.

@dconeybe
Copy link
Copy Markdown
Contributor Author

/gemini review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a 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 sequence numbers (SqliteSequenceNumber) to track updates for queries and entities in the SQLite cache database, migrating the schema from version 1.0.0 to 1.1.0. It also adds a lexicographical comparison utility for byte arrays to support comparing ImmutableByteArray instances on older Android API levels. The review feedback highlights opportunities to simplify string concatenations by removing redundant empty strings in DataConnectCacheDatabaseMigrator.kt.

@dconeybe dconeybe marked this pull request as ready for review May 28, 2026 17:35
@dconeybe dconeybe merged commit 2fd9dc6 into main May 28, 2026
52 checks passed
@dconeybe dconeybe deleted the dconeybe/RealtimeCacheUpdate2 branch May 28, 2026 20:28
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.

2 participants