Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observe Single event method returning cached data #84

Closed
spandana-batchu opened this issue Jun 15, 2017 · 9 comments
Closed

Observe Single event method returning cached data #84

spandana-batchu opened this issue Jun 15, 2017 · 9 comments
Assignees

Comments

@spandana-batchu
Copy link

[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment

  • Xcode version: 8.3
  • Firebase SDK version: 3.1
  • Library version:
  • Firebase Product: database

[REQUIRED] Step 3: Describe the problem

We are facing the below issue on our iOS app that uses firebase iOS SDk.
To give you some context, the users of our app are part of Groups. Each of these groups have some group information.
In the database we have user who is mapped with a list of group IDs. Using these Group Ids Further we fetch group’s info. Below is the structure.

+User1
    +GroupID1
        +timestamp
    +GroupID2
        +timestamp
+GroupID1
    +groupName:
    +groupCount:……
    +timestamp

Whenever there is a change in group’s info, we have a firebase cloud fuction that updates the timestamp at both the places. Hence any change to group’s info would notify the observers at both references database\GroupID1 and database\User1
The issue we are facing is that we have a continuous observer at reference database\User1 using the method observe event type.
Changes to group info is notifying that continuous observer as expected. After which we are fetching group info using observe single event method. But that group info returned is the cached info.
The info returned at reference database\GroupID1 is always one step old data.
Is there anything we are missing here.

Relevant Code:

observer at reference database\User1 :

observe(_ eventType: .value, with block: @escaping (FIRDataSnapshot) -> Swift.Void, withCancel cancelBlock: ((Error) -> Swift.Void)? = nil) -> UInt

observer at reference database\ GroupID1 :

observeSingleEvent(of eventType: .value, andPreviousSiblingKeyWith block: @escaping (FIRDataSnapshot, String?) -> Swift.Void)

@schmidt-sebastian
Copy link
Contributor

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.

@cbess
Copy link

cbess commented Jul 27, 2017

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.

XiangtianDai pushed a commit that referenced this issue Jul 28, 2017
* Adds “reset password in app” to sample app

* Addresses comments

* Addresses comments
XiangtianDai added a commit that referenced this issue Jul 29, 2017
* Adds passing state and continue URL in OOBCodes actions. (#82)

* Adds actionCodeSettings class (#83)

* Adds FIRActionCodeSettings class

* Removes iOSAppStoreId to reflect update spec.

* Adds “reset password in app” to sample app (#84)

* Adds “reset password in app” to sample app

* Addresses comments

* Addresses comments

* Adds @param documentation for actionCodeSettings (#85)

Adds @param documentation for actionCodeSettings in FIRGetOOBConfirmationCodeRequest.

* Adds request configuration class

Adds a class that will comprise of all configurations needed to make a request to the Firebase Auth backend; including APIKey and Language code in the future.

* Addresses comments.

* Adds Setting Language

Add Setting Language Feature to Firebase Auth.

- Only adds support for two languages (English and Spanish) in this change. (Also supports two languages in test), more to come after this change is accepted.

- For now sample app tests language setting only when using “reset password in app” option, the email sent will be in the current app language.  Additional tests to come after change is accepted.

* Amends code for unit tests

Will add more comprehensive testing when code accepted.

* Ecodes strings files in UTF-8

* Addresses comments

* Addresses comments

* Remove comments in .strings

* Adds remaining TC languages to Firebase Auth.

* Add line break to .strings files

* remove language code english fallback

Remove the fallback that sends “en” as the language code to the backend if no language code is specified.

* addresses comment

* Fixes FIRSecureToken Crash

Integrates FIRSecureTokenService and FIRSecureTokenRequest with FIRAuthRequestConfiguration.

* Addresses comment

* Add auth language input

Adds Auth language input to the Sample App in preparation for manual testing.

* removes unnecessary comment

* address comments

* Add app language option

Allow user to set the current app language code as the auth language code.  This is in preparation for manual testing before release.

* Addresses Comment

* Adds missing continue URI

Adds missing continue URL to Firebear error handling.

* Remove unused line

Removes unused line from FIRPhoneAuthProvider.m

* Moves the new public header to the right place.

* Fixes broken macOS build.

* Removes trailing spaces.

* Addresses review comments.
@MarksCode
Copy link

Any update?

@paulb777
Copy link
Member

@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.

@quanvo87
Copy link

quanvo87 commented Jan 3, 2018

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.

@morganchen12
Copy link
Contributor

@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?

@quanvo87
Copy link

quanvo87 commented Jan 4, 2018

@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.

@morganchen12
Copy link
Contributor

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.

minafarid pushed a commit to minafarid/firebase-ios-sdk that referenced this issue Jun 6, 2018
* Adds passing state and continue URL in OOBCodes actions. (firebase#82)

* Adds actionCodeSettings class (firebase#83)

* Adds FIRActionCodeSettings class

* Removes iOSAppStoreId to reflect update spec.

* Adds “reset password in app” to sample app (firebase#84)

* Adds “reset password in app” to sample app

* Addresses comments

* Addresses comments

* Adds @param documentation for actionCodeSettings (firebase#85)

Adds @param documentation for actionCodeSettings in FIRGetOOBConfirmationCodeRequest.

* Adds request configuration class

Adds a class that will comprise of all configurations needed to make a request to the Firebase Auth backend; including APIKey and Language code in the future.

* Addresses comments.

* Adds Setting Language

Add Setting Language Feature to Firebase Auth.

- Only adds support for two languages (English and Spanish) in this change. (Also supports two languages in test), more to come after this change is accepted.

- For now sample app tests language setting only when using “reset password in app” option, the email sent will be in the current app language.  Additional tests to come after change is accepted.

* Amends code for unit tests

Will add more comprehensive testing when code accepted.

* Ecodes strings files in UTF-8

* Addresses comments

* Addresses comments

* Remove comments in .strings

* Adds remaining TC languages to Firebase Auth.

* Add line break to .strings files

* remove language code english fallback

Remove the fallback that sends “en” as the language code to the backend if no language code is specified.

* addresses comment

* Fixes FIRSecureToken Crash

Integrates FIRSecureTokenService and FIRSecureTokenRequest with FIRAuthRequestConfiguration.

* Addresses comment

* Add auth language input

Adds Auth language input to the Sample App in preparation for manual testing.

* removes unnecessary comment

* address comments

* Add app language option

Allow user to set the current app language code as the auth language code.  This is in preparation for manual testing before release.

* Addresses Comment

* Adds missing continue URI

Adds missing continue URL to Firebear error handling.

* Remove unused line

Removes unused line from FIRPhoneAuthProvider.m

* Moves the new public header to the right place.

* Fixes broken macOS build.

* Removes trailing spaces.

* Addresses review comments.
@Rahish
Copy link

Rahish commented May 8, 2019

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)
        }

@firebase firebase locked and limited conversation to collaborators Nov 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants