-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Lockdown firebase arrays and improve index add performance #898
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
Conversation
Signed-off-by: Alex Saveau <[email protected]>
@samtstern Could you make a To address your comment:
You can mock final symbols, it's just not a stable api yet. Does that work? |
Signed-off-by: Alex Saveau <[email protected]>
The mocking of final things does not play nice with Android, I tried really hard to get it to work before giving up :-( And yep, will make that branch. Will branch 3.0 from 2.3.1-dev to start |
@samtstern Oh well, that's too bad. 😢 I'll make the classes non-final and keep the other changes. |
Signed-off-by: Alex Saveau <[email protected]>
@@ -243,10 +244,14 @@ public String toString() { | |||
/** | |||
* A ValueEventListener attached to the joined child data. | |||
*/ | |||
protected class DataRefListener implements ValueEventListener { | |||
private final class DataRefListener implements ValueEventListener { |
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.
Missed one!
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.
That shouldn't matter, right? We're making it private so it's not mockable anyway.
I dont't want to bother you, but wanted to ask why this approach is more efficient? |
@Eragon29 we don't have to query for the correct index on addition. |
@SUPERCILEX Ah, now I get it. |
👍 |
Here's my reasoning behind the change:
I'm personally a culprit here, I've never really bothered thinking about how devs would extend our firebase arrays. Take the
FirebaseIndexArray
for example. Let's say a developer wants to overrideonKeyAdded
:FirebaseUI-Android/database/src/main/java/com/firebase/ui/database/FirebaseIndexArray.java
Lines 178 to 185 in d871c7a
All of the fields referenced in there are private so the developer would also have to override
onKey[Changed/Removed/Moved]
. Since they had to reimplement those methods, they also have to reimplementDataRefListener
since it accesses private fields. And then all the other methods are private so at this point the developer has just reimplemented the whole class and there's no point in extending it in the first place. As for getting the callbacks, they should just be using ourChangeEventListener
api.As you can see in this PR, I was able to improve performance by breaking backwards compatibility.
Using inheritance (on lists especially) is poor practice and we should encourage developers to use inheritance.