0

I'm trying to receive my last 4 items on my DB (because the last one is the newest item).

  task3 = await FirebaseDatabase.DefaultInstance.GetReference("users/").OrderByKey().LimitToLast(4).GetValueAsync().ContinueWith(t => t);
  foreach (DataSnapshot s in d.Children)
            { Debug.Log(s.Key);}

This code works fine, I really get my last 4 items,

But then I add a new user to my Users DB from another device and I run the same code above from my first device (Unity Editor) but still get the same 4 items as before without the new one.

The code is correct because if I stop the game on Unity and reset the app, I get the right values.
I can't get the updated values without resetting the app, what am I missing?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
SHAI
  • 789
  • 3
  • 10
  • 43
  • Two questions: 1) Are you using disk persistence? 2) if you run the same code a second time on the device with the problem, does it then show the correct values? – Frank van Puffelen Jun 03 '20 at 03:22
  • I don't use disk persistence. Yes I run the same code on the device with the problem (first device) and I still see the old values unless I stop the app and play again and run the same code – SHAI Jun 03 '20 at 03:32
  • Interesting. My first thought was that you ended up seeing values from the cache, but that doesn't seem to be the case. I'm notr sure what else it could be, so am hoping that someone else spots the problem. – Frank van Puffelen Jun 03 '20 at 03:43
  • 1
    There's something interesting even more, if I remove .OrderByKey().LimitToLast(4) from my command and get all the keys- I get the new keys without need to reset the app – SHAI Jun 03 '20 at 04:00
  • https://firebase.google.com/docs/hosting/manage-cache – derHugo Jun 03 '20 at 05:44
  • @derHugo SHAI is using Firebase Realtime Database, not Firebase Hosting (or at least not here). – Frank van Puffelen Jun 03 '20 at 15:18
  • @FrankvanPuffelen would it be [this](https://stackoverflow.com/a/59777844/7111561) then? – derHugo Jun 03 '20 at 15:19
  • That's why my first question was about disk persistence. Given that SHAI isn't using that, it seems that can't be the cause. But I admit that I have no clear idea what the cause is likely to be at this point. – Frank van Puffelen Jun 03 '20 at 16:04
  • I want to add another thing- if I add query.ValueChanged += (sender, e)=>{ I do get the new values, does Firebase force us to use listeners? I don't want to use them, I expect to get new results when calling GetValueAsync without listeners – SHAI Jun 03 '20 at 16:39

0 Answers0