step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
668 stars 168 forks source link

Missing updates from the Realtime Database #321

Open KaipoCraft opened 4 weeks ago

KaipoCraft commented 4 weeks ago

Hi! Thank y'all for this project. I'm using the Subscribe() function and it seems like it occasionally misses deletion events. I set up this simple function to update a dictionary. Is this the proper way to interact with this? What might be a more thread-safe version of this assuming that it's a race condition?

    .AsObservable<JToken>()
    .Subscribe(d =>
    {
        if (d.EventType == Firebase.Database.Streaming.FirebaseEventType.InsertOrUpdate)
        {
            if (currentItems.ContainsKey(d.Key))
            {
                // Update item in dictionary
                currentItems[d.Key] = d.Object;
            }
            else
            {
                // Add item to dictionary
                currentItems.Add(d.Key, d.Object);
            }
        }
        else if (d.EventType == Firebase.Database.Streaming.FirebaseEventType.Delete)
        {
            // Remove item from dictionary
            currentItems.Remove(d.Key);
        }
    });