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

.cache() requeries API #1417

Closed
jvanbruegge opened this issue Mar 2, 2016 · 10 comments
Closed

.cache() requeries API #1417

jvanbruegge opened this issue Mar 2, 2016 · 10 comments

Comments

@jvanbruegge
Copy link

This is my reopening of the issue #1405
My main issue is gone with saving getStuff().cache() to a local is gone, but I still get aborted requeries of the API, that should not be thrown because the code is in the getStuff() method.
Here is a screenshot of Chrome's network tab: http://qs.lc/sb5k0 (plants is the URL)
I have no idea, why they are aborted and I have no idea why they are queried at all.
Thanks.

@jvanbruegge
Copy link
Author

Ok, in addition to that, when I have a second service, taking the ModelStream and querying additional information for the contents of the observable and cache an observable of a data structure like this:

export class dataStructure
{
constructor(public model : Model, public information : Observable<secondModel>){}
}

I get cascading updates resulting in an endless loop. The root of the loop is the Observable.of method. The function that im calling gets called once, but the Observable.of creates an infinite amount of Observables. Shouldn't cache() make an observable hot? Even putting share() all over the method didn't help.

@jvanbruegge
Copy link
Author

Ok, I found the issue with the cascading updates:

private getParameters() : Observable<ParameterObservableArray>
    {
        return this.plantService.PlantStream
        .map<ParameterObservableArray>(plant => {
            return new ParameterObservableArray(
                plant,
                this.getParametersOfPlant(plant).cache() //the .cache() was missing
            );
        });
    }

I had to cache the subqueries too (so now I have a global variable that stores getParameters().cache() and the function itself caches)

But I still have the requering (that is not that bad, but I don't think it should be there)
EDIT: I get the requeries only for the getStuff(), not the additional information, which is weird

@jvanbruegge
Copy link
Author

OK, I made a third service, adding additional information to the additional information of the second service (thus creating a meta-meta-stream) and I get the aborted requeries there as well. So only the one in the middle doesnt do so

@trxcllnt
Copy link
Member

trxcllnt commented Mar 2, 2016

@SuperManitu do you have an isolated repro example (in plunkr, jsbin, esbin, etc.) we can see and run? That'll help us determine whether there's a bug in Rx or if you need to something differently.

@jvanbruegge
Copy link
Author

I tried here: https://plnkr.co/edit/0nw7hDqtSRjycBmNcV6X?p=preview
but I can't get it working, but something like this is my setup

@jvanbruegge
Copy link
Author

https://plnkr.co/edit/0nw7hDqtSRjycBmNcV6X?p=preview
it's working now. If you look in the console, you see two times an url, in a part of the code that should be cached
EDIT: Well the plunker works as intended, with only one GET call, but in the same setup for me I get two calls.

@jvanbruegge
Copy link
Author

I found my issue, I had a get property that was taking the stored Observable and transforms it like this:
this.stream.flatMap<Model>(array => Observable.from(array, x => x))
Is this intended? Seems odd to me, caching this value, too. And I have a location in my code where I'm not able to cache it. Does this mean I have to accept the additional calls?

@benlesh
Copy link
Member

benlesh commented Mar 4, 2016

@SuperManitu We're going to need code that can reproduce this issue that is actually using the latest version of RxJS 5. From your plunker, this appears to be some version of RxJS 5 that is associated to Angular 2 beta.0... I'm not sure how stale that is, but it's probably several versions behind.

@benlesh
Copy link
Member

benlesh commented Mar 4, 2016

Since I can't reproduce this in current versions of RxJS 5. I'm not sure what course of action to take here. I'm going to close this for now, @SuperManitu. If you can come up with minimal code that reproduces this in RxJS 5.0.0-beta.2, then please do reopen, as we'd definitely want to fix it ASAP.

@lock
Copy link

lock bot commented Jun 7, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants