Giter Site home page Giter Site logo

Comments (9)

schmidt-sebastian avatar schmidt-sebastian commented on May 14, 2024

Thanks for sending over this issue. While I understand that this can be frustrating, this is expected behavior. Single even observers will return data from the cache if there is data available. This allows us to fire them immediately. If you use .value observers, you will receive updated data in its second call.

from firebase-ios-sdk.

cbess avatar cbess commented on May 14, 2024

I suppose this makes sense. But, is there a way to do have it pull from the server immediately/initially, without having to call it twice? Am I suppose to use the non-single event methods, then cancel the observer manually?

Also, I would say the documentation should be updated.

from firebase-ios-sdk.

MarksCode avatar MarksCode commented on May 14, 2024

Any update?

from firebase-ios-sdk.

paulb777 avatar paulb777 commented on May 14, 2024

@MarksCode What kind of update are you looking for? This issue was closed as "expected behavior". stackoverflow is a better place to ask usage questions.

from firebase-ios-sdk.

quanvo87 avatar quanvo87 commented on May 14, 2024

Is there a better way of doing this? I've noticed that when using a cache and attempting a singleEvent query, it can take 55-60 attempts before fresh data is returned.

from firebase-ios-sdk.

morganchen12 avatar morganchen12 commented on May 14, 2024

@quanvo87 load time is going to depend on the size of the data you're loading and the quality of your internet connection. Are you observing one minute load times for small queries on good internet?

from firebase-ios-sdk.

quanvo87 avatar quanvo87 commented on May 14, 2024

@morganchen12 When testing this, I was querying an endpoint that returned a small String. My connection is 15 ping 50/10 down/up. I could probably be more clear--by 55-60 attempts, what I mean is I did a ref.observeSingleEvent, and in the callback, if !snapshot.exists(), print something and repeat the function, until it finally got back data. The print statement executed 50+ times each test run. This is with persistence enabled. With persistence disabled, it just fires once.

from firebase-ios-sdk.

morganchen12 avatar morganchen12 commented on May 14, 2024

Oh, I misread your last comment.

With the current API, observing a single event with persistence enabled doesn't let you specify whether you're trying to retrieve cached or server data. The SDK defaults to returning cached data, but this isn't useful if you're trying to retrieve server data. For the time being you should use value listeners instead like Sebastian mentioned above, but this does seem like a non-feature.

from firebase-ios-sdk.

Rahish avatar Rahish commented on May 14, 2024

Thanks for sending over this issue. While I understand that this can be frustrating, this is expected behavior. Single even observers will return data from the cache if there is data available. This allows us to fire them immediately. If you use .value observers, you will receive updated data in its second call.

Why in the Second call? As we expect refreshed data whenever we apply the observer to the Database Reference. I tried below code too, its also not refreshing the data
weak var weakSelf = self
valueRef = dbRef?.observe(.value) { (snapShotData) in

            if singleValueObserver
            {
                weakSelf?.dbRef?.removeObserver(withHandle: weakSelf?.valueRef ?? 0)
            }
            weakSelf?.dataFetched(snapShotData)
        }

from firebase-ios-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.