Skip to content

fix(database): apply filtered getData results only to the query's view - #16722

Open
paulb777 wants to merge 3 commits into
mainfrom
pb-rtdb-get-filtered-14137
Open

paulb777 wants to merge 3 commits into
mainfrom
pb-rtdb-get-filtered-14137

Conversation

@paulb777

@paulb777 paulb777 commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #14137
Fixes #8286

Problem

getData applied its result with applyServerOverwriteAtPath: at the query's location, even for a query with a limit or range. That result is only part of the data at the location, so the overwrite replaced:

Fix

FRepo getData: now calls a new -[FSyncTree applyGetResultForQuery:newData:]. For a query that loads all data, it still applies a server overwrite. For any other query, it applies the result the way the JS SDK's repoGetValue does:

  1. Add a registration for the query without starting a listen, so the query has a view and a tag.
  2. Apply the result as a tagged overwrite. This only updates that view, and it merges into the persisted cache.
  3. Remove the registration without stopping a listen. This also removes the tag.

The registration is a new FKeepSyncedEventRegistration instance. It raises no events and only matches itself, so an existing listener or keepSynced registration on the same query stays in place and gets the result.

addEventRegistration: and removeEventRegistration: get private variants with skipListenerSetup and skipListenerDedup flags, like the JS SDK's skipSetupListener and skipListenerDedup.

This is separate from #12168, which #16721 fixes. Thanks to @diegogarciar and @fawzialrifai for the reports.

Testing

  • 7 new unit tests in FSyncPointTests.m for applyGetResultForQuery:newData:. These 4 fail without the fix:

    • a filtered view at the same location keeps its data
    • a view without a filter at the same location keeps its data
    • a view below the location keeps its data
    • the persisted server cache keeps the data that isn't in the result

    The other 3 check that a get starts and stops no listens and leaves no tag, keeps a keepSynced query synced, and raises events for a listener on the same query.

  • 4 new integration tests in FIRDatabaseQueryTests.m for the same 4 cases. All 4 fail without the fix.

  • DatabaseUnit (SPM, macOS): 436 tests pass.

  • FIRDatabaseQueryTests, FKeepSyncedTest and FPersist integration tests, against the RTDB emulator: 139/139 pass.

  • Merged with fix(database): resend in-flight gets after reconnect #16719, fix(database): avoid crash on get error without reason #16720 and fix(database): return child data from getData under observed parent #16721, only CHANGELOG.md conflicts. The first commit of this PR also passed the unit and integration tests in that merge (447 and 140 tests).

…4137)

getData applied its result as a server overwrite at the query's
location, even for a query with a limit or range, whose result is only
part of the data there. Other listeners at or below the location, and
the disk cache, lost the data that wasn't in the result. For example,
after a get for the three children before "f", a listener for the
children from "f" on at the same location had no children.

Now, like the JS SDK's get(), a filtered result is applied only to a
view for the query, which the sync tree adds without a listen for the
duration of the update. The disk cache merges the result instead of
replacing the data at the location. Results of queries that load all
data are still applied as a server overwrite.
@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.

@paulb777

Copy link
Copy Markdown
Member 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 fixes an issue where calling getData on a query with a limit or range could incorrectly remove data from other listeners at or below the query's location, as well as from the disk cache. It introduces applyGetResultForQuery:newData: in FSyncTree to apply the query result specifically to the query's own view without setting up a persistent listen or triggering unnecessary listener changes. This is achieved by adding helper methods to skip listener setup and deduplication during registration and removal. Comprehensive integration and unit tests have been added to verify this behavior. There are no review comments, so I have no feedback to provide.

…d getData (#8286)

The getData fix for #14137 also fixes #8286, where a listener without a filter fired again with only the child that a queryEqualToValue: get returned.
@paulb777

Copy link
Copy Markdown
Member 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 addresses an issue where calling getData on a query with a limit or range could incorrectly remove data from other listeners at or below the query's location, as well as from the disk cache. To resolve this, the changes introduce applyGetResultForQuery:newData: in FSyncTree to apply the query result specifically to its own view without triggering a full server overwrite, utilizing temporary event registrations that skip listener setup and deduplication. Comprehensive integration and unit tests have been added to verify this behavior. There are no review comments, so I have no additional feedback to provide.

@ncooke3 ncooke3 modified the milestones: 13.1.0 - M188, 13.2.0 - M189 Oct 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants