I am trying to poll my realtime database every 3 seconds with the iOS SDK to retrieve the latest 5 message objects.
I use the following code:
let query = rtdb.child("event/ID/chat")
.queryOrdered(byChild: "createdAt")
.queryStarting(atValue: <TIMESTAMP>)
.queryLimited(toFirst: 5)
query.observeOnce(of: eventType) { snapshot in }
Let's say I have the following (simplified) data in my db:
{
id: 1,
createdAt: 123456781
},
{
id: 2,
createdAt: 123456782
},
{
id: 3,
createdAt: 123456783
},
{
id: 4,
createdAt: 123456784
},
{
id: 5,
createdAt: 123456785
},
{
id: 6,
createdAt: 123456786
},
I start my query with the timestamp 123456787
. I then post another message with the timestamp 123456788
. My query does not pick it up. Why?
If I instead start my query with the timestamp 123456782
, it will return the messages with id 2, 3, 4, 5
.
What am I doing wrong?
UPDATE
It's because of persistence being enabled. It just returns the locally cached data. That's stupid.