step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
670 stars 170 forks source link

Synchronization issues with Realtime Database and a possible solution #124

Closed MathewSachin closed 6 years ago

MathewSachin commented 6 years ago

RealtimeDatabase is not receiving streaming events from Firebase except put when a new item is added and keep alive.

So, when an element is edited no notification is received.

A possible fix is to change the line: https://github.com/step-up-labs/firebase-database-dotnet/blob/2392df1860971ff188cce305078f97eb78a91e31/src/Firebase/Offline/RealtimeDatabase.cs#L264

to just:

var query = this.childQuery; 

I suppose the main problem is with the StartAt method which is preventing notifications related to any elements whose key appears before the latest key.

bezysoftware commented 6 years ago

Which would also mean that if you have 10000 elements in the DB, all of them would need to be fetched each time your app is run. That's not desired

MathewSachin commented 6 years ago

I agree that you are right in that way. But, if I want notification in change of elements, is there any other way.

The data for my application is quite small. What I'm doing is keeping multiple instances of RealtimeDatabase objects and then created ObservableCollections from them.

So, I want to have my ObservableCollection up to date with the data on Firebase.

I appreciate your help.

bezysoftware commented 6 years ago

I gave it a quick thought and I agree there should be an option to do what you need. I just pushed a change which allow this - use one of the overloads for AsRealtimeDatabase which will allow you to specify StreamingOptions - and just set it to Everything. That should do the trick.

Here's the commit https://github.com/step-up-labs/firebase-database-dotnet/commit/05aae6c88d142670ec20605e01f95ab06988180b Nuget will be available once it gets indexed, v3.3.0

MathewSachin commented 6 years ago

Thank you! Awesome job. I'll test the nuget version and let you know.

MathewSachin commented 6 years ago

Works perfectly. Thank you!