-
Notifications
You must be signed in to change notification settings - Fork 616
get() reimplementation #3887
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
Merged
Merged
get() reimplementation #3887
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3e085d4
Updated getValue so that it doesn't update the SyncTree
maneesht 34e251d
Fixed formatting issues
maneesht dcdff66
WIP
maneesht 7b6f9f4
Merge remote-tracking branch 'origin/master' into mtewani/fix-get-cache
maneesht bec3e87
Merge remote-tracking branch 'origin/master' into mtewani/fix-get-cache
maneesht 0276e1c
Merge remote-tracking branch 'origin/master' into mtewani/fix-get-cache
maneesht 606b9c1
Used addEventRegistration and removeEventRegistration to add to the t…
maneesht 299c2df
Fixed test and ran formatter
maneesht 02af45d
Added comments
maneesht 1babdc2
Fixed formatting
maneesht 989f124
Added test annotation
maneesht 8002947
WIP
maneesht b95be2c
get test suggest
jmwski 6f5861a
WIP
maneesht 3f3813a
Removed extra event propagation
maneesht 13e2dc5
Included more tests
maneesht 481acd7
Added missing link
maneesht 69b4bef
Fixed formatting
maneesht cc6e3a1
Fixed formatting
maneesht cc70e55
Reverted retryrule to 3
maneesht 1d58f9c
Resolved all TODOs
maneesht 5cee9c7
Removed unnecessary nesting
maneesht d9a97f2
Removed event listener. WIP
maneesht 23bde0b
Fixed tests
maneesht e60273c
Removed comment
maneesht 94c91fc
Removed comment
maneesht 844c8cc
Addressed comments
maneesht 3bdf63a
Removed usage of 34L
maneesht a590590
Removed question
maneesht 67bf0ce
Addressed comments
maneesht 15bbeda
Fixed formatting
maneesht 2d7b15f
Addressed comments
maneesht 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
350 changes: 323 additions & 27 deletions
350
firebase-database/src/androidTest/java/com/google/firebase/database/QueryTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -538,9 +538,14 @@ public Node getServerValue(QuerySpec query) { | |
}); | ||
} | ||
|
||
/** Add an event callback for the specified query. */ | ||
public List<? extends Event> addEventRegistration( | ||
@NotNull final EventRegistration eventRegistration) { | ||
return addEventRegistration(eventRegistration, false); | ||
} | ||
|
||
/** Add an event callback for the specified query. */ | ||
public List<? extends Event> addEventRegistration( | ||
@NotNull final EventRegistration eventRegistration, final boolean skipListenerSetup) { | ||
return persistenceManager.runInTransaction( | ||
new Callable<List<? extends Event>>() { | ||
@Override | ||
|
@@ -635,7 +640,7 @@ public List<? extends Event> call() { | |
WriteTreeRef writesCache = pendingWriteTree.childWrites(path); | ||
List<? extends Event> events = | ||
syncPoint.addEventRegistration(eventRegistration, writesCache, serverCache); | ||
if (!viewAlreadyExists && !foundAncestorDefaultView) { | ||
if (!viewAlreadyExists && !foundAncestorDefaultView && !skipListenerSetup) { | ||
View view = syncPoint.viewForQuery(query); | ||
setupListener(query, view); | ||
} | ||
|
@@ -650,7 +655,19 @@ public List<? extends Event> call() { | |
* <p>If query is the default query, we'll check all queries for the specified eventRegistration. | ||
*/ | ||
public List<Event> removeEventRegistration(@NotNull EventRegistration eventRegistration) { | ||
return this.removeEventRegistration(eventRegistration.getQuerySpec(), eventRegistration, null); | ||
return this.removeEventRegistration( | ||
eventRegistration.getQuerySpec(), eventRegistration, null, false); | ||
} | ||
|
||
public List<Event> removeEventRegistration( | ||
@NotNull EventRegistration eventRegistration, boolean skipDedup) { | ||
return this.removeEventRegistration( | ||
eventRegistration.getQuerySpec(), eventRegistration, null, skipDedup); | ||
} | ||
|
||
public List<Event> removeEventRegistration( | ||
QuerySpec query, @NotNull EventRegistration eventRegistration) { | ||
return this.removeEventRegistration(query, eventRegistration, null, false); | ||
} | ||
|
||
/** | ||
|
@@ -660,13 +677,14 @@ public List<Event> removeEventRegistration(@NotNull EventRegistration eventRegis | |
*/ | ||
public List<Event> removeAllEventRegistrations( | ||
@NotNull QuerySpec query, @NotNull DatabaseError error) { | ||
return this.removeEventRegistration(query, null, error); | ||
jmwski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this.removeEventRegistration(query, null); | ||
} | ||
|
||
private List<Event> removeEventRegistration( | ||
final @NotNull QuerySpec query, | ||
final @Nullable EventRegistration eventRegistration, | ||
final @Nullable DatabaseError cancelError) { | ||
final @Nullable DatabaseError cancelError, | ||
final boolean skipDedup) { | ||
return persistenceManager.runInTransaction( | ||
new Callable<List<Event>>() { | ||
@Override | ||
|
@@ -688,6 +706,7 @@ public List<Event> call() { | |
if (maybeSyncPoint.isEmpty()) { | ||
syncPointTree = syncPointTree.remove(path); | ||
} | ||
|
||
List<QuerySpec> removed = removedAndEvents.getFirst(); | ||
cancelEvents = removedAndEvents.getSecond(); | ||
// We may have just removed one of many listeners and can short-circuit this whole | ||
|
@@ -701,6 +720,25 @@ public List<Event> call() { | |
persistenceManager.setQueryInactive(query); | ||
removingDefault = removingDefault || queryRemoved.loadsAllData(); | ||
} | ||
|
||
/** | ||
* This is to handle removeRegistration by {@link Repo#getValue(Query)}. Specifically | ||
* to avoid the scenario where: A listener is attached at a child path, and {@link | ||
* Repo#getValue(Query)} is called on the parent path. Normally, when a listener is | ||
* attached on a child path and then a parent path has a listener attached to it, to | ||
* reduce the number of listeners, the listen() function will unlisten to the child | ||
* path and listen instead on the parent path. And then, when removeRegistration is | ||
* called on the parent path, the child path will get listened to, since it doesn't | ||
* have anything covering its path. However, for {@link Repo#getValue(Query)}, we do | ||
* not call listen on the parent path, and the child path is still listened to and so | ||
* when the deduping happens below, the SyncTree assumes that the child listener has | ||
* been removed and attempts to call listen again, but since we are still listening on | ||
* that location, listen would be called twice on the same query. skipDedup allows us | ||
* to skip this deduping process altogether. | ||
*/ | ||
if (skipDedup) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we are leaking the tag created inside keepSynced(true) in Repo.getValue because we never hit L790. |
||
return null; | ||
} | ||
ImmutableTree<SyncPoint> currentTree = syncPointTree; | ||
boolean covered = | ||
currentTree.getValue() != null && currentTree.getValue().hasCompleteView(); | ||
|
@@ -915,7 +953,7 @@ private QuerySpec queryForTag(Tag tag) { | |
} | ||
|
||
/** Return the tag associated with the given query. */ | ||
private Tag tagForQuery(QuerySpec query) { | ||
public Tag tagForQuery(QuerySpec query) { | ||
return this.queryToTagMap.get(query); | ||
} | ||
|
||
|
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
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.