-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix(sql_connect): Refactor to improve caching performance for large result sets #18430
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
Open
aashishpatil-g
wants to merge
5
commits into
main
Choose a base branch
from
ap/cacheIsolate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7d9b76e
fix: Refactor to use separate Isolate for Cache
aashishpatil-g 877bac5
Address Gemini feedback
aashishpatil-g d1e4ec4
fix integration test failure
aashishpatil-g 9e72e42
Fix isolate errors when running on wasm
aashishpatil-g b0c0887
Address @lyokone's feedback
aashishpatil-g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
244 changes: 204 additions & 40 deletions
244
...se_data_connect/firebase_data_connect/example/dataconnect/.dataconnect/schema/prelude.gql
Large diffs are not rendered by default.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
packages/firebase_data_connect/firebase_data_connect/example/integration_test/cache_e2e.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright 2026, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:firebase_data_connect/firebase_data_connect.dart'; | ||
| import 'package:firebase_data_connect_example/generated/movies.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| import 'query_e2e.dart'; // For deleteAllMovies | ||
|
|
||
| void runCacheTests() { | ||
| group( | ||
| '$FirebaseDataConnect cache', | ||
| () { | ||
| setUp(() async { | ||
| final dataConnect = MoviesConnector.instance.dataConnect; | ||
| // Temporarily disable cache during database cleanup to prevent populating it | ||
| dataConnect.cacheSettings = null; | ||
| dataConnect.useDataConnectEmulator('127.0.0.1', 9399); | ||
|
|
||
| await deleteAllMovies(); | ||
|
|
||
| // Enable cache with memory storage and a large TTL for testing. | ||
| dataConnect.cacheSettings = CacheSettings( | ||
| storage: CacheStorage.memory, | ||
| maxAge: const Duration(minutes: 5), | ||
| ); | ||
| // Re-apply emulator to force cache manager recreation with new settings | ||
| dataConnect.useDataConnectEmulator('127.0.0.1', 9399); | ||
| }); | ||
|
|
||
| testWidgets('test cache flow: serverOnly, cacheOnly, preferCache', | ||
| (WidgetTester tester) async { | ||
| final moviesConnector = MoviesConnector.instance; | ||
|
|
||
| // 1. Initial query with preferCache should result in server hit because cache is empty. | ||
| final res1 = await moviesConnector.listMovies().ref().execute( | ||
| fetchPolicy: QueryFetchPolicy.preferCache, | ||
| ); | ||
| expect(res1.source, DataSource.server); | ||
| expect(res1.data.movies, isEmpty); | ||
|
|
||
| // 2. Second query with preferCache should result in cache hit. | ||
| final res2 = await moviesConnector.listMovies().ref().execute( | ||
| fetchPolicy: QueryFetchPolicy.preferCache, | ||
| ); | ||
| expect(res2.source, DataSource.cache); | ||
| expect(res2.data.movies, isEmpty); | ||
|
|
||
| // 3. Mutation to add a movie. This goes to server. | ||
| await moviesConnector | ||
| .createMovie( | ||
| genre: 'Sci-Fi', | ||
| title: 'Inception', | ||
| releaseYear: 2010, | ||
| ) | ||
| .ref() | ||
| .execute(); | ||
|
|
||
| // 4. Query with cacheOnly should still return empty list (cache hit, stale data). | ||
| final res3 = await moviesConnector.listMovies().ref().execute( | ||
| fetchPolicy: QueryFetchPolicy.cacheOnly, | ||
| ); | ||
| expect(res3.source, DataSource.cache); | ||
| expect(res3.data.movies, isEmpty); | ||
|
|
||
| // 5. Query with serverOnly should return the new movie (server hit) and update cache. | ||
| final res4 = await moviesConnector.listMovies().ref().execute( | ||
| fetchPolicy: QueryFetchPolicy.serverOnly, | ||
| ); | ||
| expect(res4.source, DataSource.server); | ||
| expect(res4.data.movies.length, 1); | ||
| expect(res4.data.movies[0].title, 'Inception'); | ||
|
|
||
| // 6. Query with cacheOnly should now return the new movie (cache hit). | ||
| final res5 = await moviesConnector.listMovies().ref().execute( | ||
| fetchPolicy: QueryFetchPolicy.cacheOnly, | ||
| ); | ||
| expect(res5.source, DataSource.cache); | ||
| expect(res5.data.movies.length, 1); | ||
| expect(res5.data.movies[0].title, 'Inception'); | ||
| }); | ||
| }, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.