-
Notifications
You must be signed in to change notification settings - Fork 48
Querying lists doesn't work #9
Comments
Thanks for the issue report! I put together a demo to show what I found: Example
It looks like the query is filtering the results if you're only reading from Firebase (online and offline), but there are a few issues if writing to Firebase while offline: Issues
I'll see what I can do to fix this. Let me know if you experience anything else. Thanks! |
Yes, I have the same problem.
My logic want to select lastest data, then select 10 lastest record. However, I used angularfire2, that's OK. No problem. |
I have the same problem with AFO 2.0.3. I have a dashboard, where I fetch all available tasks for all projects:
On a project detail page, I have the tasks listed by project:
I get the whole task list of all projects for each project, when I first visit the dashboard. When I first visit a project page I always get the result of this query for all later queries on tasks. I digged a bit into the code of AFO. I |
This should be fixed as of AngularFire2 Offline v4.1.1 🎉🎉 Please post if you're still experiencing issues. Thanks! |
Hi @adriancarriger I update angularfire2 offline to v4.1.1, but the problem still working. I'm using equalTo in my query. |
Hi @rodrifmed, I just tried the |
Hi @adriancarriger, The problema occurs when you execute the query with a equalTo, and them execute the same query with another value. The query always return the first value Like this example: Data:
the hight return is [z], but is returning [X,Y] |
I just made an update that supports multiple queries to the same Firebase reference in AngularFire2 Offline version 4.1.2 Here is a live demo that has an Here is the code for the example. Let me know if this is working for you. Thanks! |
@adriancarriger Still doenst work. Now the second query doenst return any value. |
@rodrifmed thanks for hanging in there! 👍 I hope this will help solve your issue: Demos
Steps to solve
Next stepsIf you can view and run the demo without an issue, then maybe there are some specific implementation details in your code that are affecting queries. If this is the case, please share as much of your code as possible or feel free to create a minimal example of the issue. Thanks! |
I had the same problem and can confirm with the update applied it works great. Thanks so much |
This example is more real: I have to make two querys, but one inside another, is because I have to wait the two querys finish.
The query is:
} |
@rodrifmed thanks for finding this! It should now be fixed in version 4.1.4. Here is a demo (with code). Can you confirm that this solves your issue? |
@adriancarriger You forgot to put first() on your example. I try without first and it's works partially, the first request brings the two lists, but the second when paging doesnt bring nothing. And the console is showing twice the not read list. |
Updated demo@rodrifmed I've updated the demo (and code) by adding the ConsoleAlso, my console is only showing one log per query. You may need to refresh the page a few times to see any new updates I posted. When you view the demo do you get different results? Here's a screenshot of what I'm seeing: PagingIt sounds like your setup is more complex than the demo I posted. Can you share the part of your code that involves paging? |
Hi @adriancarriger If you clear your storage data you will see the second query showing twice. I didnt say nothing about the pagination because I thought that if the second query had returned value, the problem would be solved. I'm using ionic infinity scroll to trigger the method to call the query with new parameters: But you could make a timeout to reproduce:
|
I upgrade to new version, and the first problem with the second query returning empty list is happening again |
Hi @rodrifmed I can confirm that the nested query is returning empty if I first clear the device's storage, and I will be working on fixing the issue. Thanks! |
@rodrifmed thanks again for pointing out this interesting issue! First I'll explain what I found, and then propose a solution. Anyone interested in the issue is welcome to chime in. Also, if you just want to know how to use Ionic infinite scroll, just go to the end of this post. What is happeningDemosIf you clear app storage before each demo you'll notice that: The only difference is that 9.4 uses Step by step
Is this a bug?
Some apps may prioritize speed over query breadth and vise versa. Possible solution 1Afo cannot know ahead of time what queries will be made to the same reference. I suggest an optional param called Proposed usageThe proposed solution would look something like this: this.afoDatabase.list('firebase/ref', {
query: {
limitToFirst: 15
},
largestQuery: {
limitToFirst: 500
}
}); Possible solution 2Another solution would be to add a boolean param called Proposed usagethis.afoDatabase.list('firebase/ref', {
query: {
limitToFirst: 15
},
waitForFirebase : true
}); Both solutions can be implemented without conflict allowing developers to use what is best for their use case. Ionic infinite scroll paging
Setup for infinite scroll/paging can already be done using Observables with a single query like this: // Properties
items: AfoListObservable<any[]>;
limit = 20;
limitObservable = new ReplaySubject(20);
constructor(private afoDatabase: AngularFireOfflineDatabase) {
// Set initial limit
this.limitObservable.next(this.limit);
// Subscribe to list
this.items = afoDatabase.list('/issues/9/9-6', {
query: {
orderByChild: 'categoryId',
limitToFirst: this.limitObservable
}
});
}
doInfinite(infiniteScroll) {
// Add 10 per page load
this.limit += 10;
// Update subject
this.limitObservable.next(this.limit);
// Call complete
setTimeout(() => infiniteScroll.complete(), 1500);
} |
Very good @adriancarriger! Could you explaine more the possible solution 2 ? |
@rodrifmed here's how solution 2 would work: Solution 2 detailsData sharingWhen multiple queries are made to a single reference they share the same "pool" of local data. During an offline write, all queries pointing to the same reference are updated without a network connection because they are all looking at the same pool of data. Shared query scopeIf there are multiple queries to a single reference and they all only need some of the total data belonging to that reference, then Afo tries to only ask Firebase for as much data as necessary to run all existing queries. For example if one query has Increasing shared scopeIf a new query comes along (e.g. Solution 2Solution 2 would allow the developer to have more control over this behavior by indicating that all updates to a specific query should wait for Firebase to return updated data if the query scope has increased. Next stepsI wanted to allow people to comment on their use cases and get feedback before implementing because this is a feature that strays from the primary list of AngularFire2 features. That said, this does seem important for managing data offline. Feel free to comment. Thanks! |
Sorry for my stupid question: |
Hi @adriancarriger, any evolution about this topic? |
I've tried to query using |
@rodrifmed do you have a preferred option (1 or 2 from above) for your use case? @ix-xerri can you show code of a full component that reproduces the issue? |
I'm simply trying to get a list of subscribed chats
It does return chats if using AngularFire but none if I use you package. |
@adriancarriger I think solution 2 better. What do you think? |
I think they both can be useful for different cases. Hopefully I can find some time to add support for solution 2 soon! 👍 |
@adriancarriger I'm sorry but I'm pretty new to Ionic and angular but I'm trying to implement this solution to the app I'm developing: https://angularfirebase.com/lessons/infinite-scroll-with-firebase-data-and-angular-animation/ |
Using the same pattern code of this example the data aren't queried as expected.
this.moData = this.db.list('/personal/routines/'+ this.authService.userId, {query: {orderByChild: 'day',equalTo: 1}});
This code gets all the data fine but the query doesn't work.
JSON of the db
Ionic info
Ionic Framework: 2.0.0
Ionic Native: 2.4.1
Ionic App Scripts: 1.1.3
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 7.4.0
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
`
The text was updated successfully, but these errors were encountered: