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

snapshotChanges with orderByChild does not return data in correct order #1246

Closed
kkbear1985 opened this issue Oct 10, 2017 · 4 comments
Closed
Assignees

Comments

@kkbear1985
Copy link

Version info

**Angular:**4.1.3

**Firebase:**4.5.0

**AngularFire:**5.0.0-rc.2

Other (e.g. Ionic/Cordova, Node, browser, operating system): ionic-angular@3.6.1

How to reproduce these conditions

since i needed metadata with my app
so i followed the guide for angular version 5 update as in https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md

and my queries is simply as below, by ordering the last edit time and limit to the first 10
this.postRef = this.maxPost.switchMap(maxPost =>
db.list('/Categories/0/', ref =>
ref.orderByChild('last_update_time').limitToFirst(maxPost)).snapshotChanges().map(actions =>
{
console.log("action is ", actions);
return actions.map(action =>{
const $key = action.payload.key;
const data = { $key, ...action.payload.val() };
return data;
` })}));``

however the actions comeback are in incorrect order as you can see in
actions[3] (it return it's prevKey as -KvRz-nXZ1lReb_M3f5J but it is actually ordered after
and -KvSiF3pRpVcmzBN59gU)
actions[7](it return it's prevKey as -KvSiF3pRpVcmzBN59gU but it is actually ordered after
and -KvcFM0f7Rab-juFtjJG)

0:{type: "child_added", payload: DataSnapshot, prevKey: null, key: "-KvRz-nXZ1lReb_M3f5J"}
1:{type: "child_added", payload: DataSnapshot, prevKey: "-KvRz-nXZ1lReb_M3f5J", key: "-KvwLPrxfYSaQRackILo"}
2:{type: "child_added", payload: DataSnapshot, prevKey: "-KvwLPrxfYSaQRackILo", key: "-KvSiF3pRpVcmzBN59gU"}
3:{type: "child_added", payload: DataSnapshot, prevKey: "-KvRz-nXZ1lReb_M3f5J", key: "-Kw5AMnsYJo1ziebush6"}
4:{type: "child_added", payload: DataSnapshot, prevKey: "-Kw5AMnsYJo1ziebush6", key: "-KvPjv1fb7kmfEGSb32o"}
5:{type: "child_added", payload: DataSnapshot, prevKey: "-KvPjv1fb7kmfEGSb32o", key: "-Kvq8WyPLASUbMNQl8ox"}
6:{type: "child_added", payload: DataSnapshot, prevKey: "-Kvq8WyPLASUbMNQl8ox", key: "-KvcFM0f7Rab-juFtjJG"}
7:{type: "child_added", payload: DataSnapshot, prevKey: "-KvSiF3pRpVcmzBN59gU", key: "-KvuA2iMvvwbxf2prNYt"}
8:{type: "child_added", payload: DataSnapshot, prevKey: "-KvuA2iMvvwbxf2prNYt", key: "-Kw04p9MLnB3Gk4WUmKv"}
9:{type: "child_added", payload: DataSnapshot, prevKey: "-Kw04p9MLnB3Gk4WUmKv", key: "-KvwIav-C_c-38dPbmrh"

@jamesdaniels jamesdaniels self-assigned this Oct 10, 2017
@jamesdaniels
Copy link
Member

I have a WIP branch that I'm cleaning up + separating into several PRs (this being one of them) now.

@kkbear1985
Copy link
Author

after some digging, i think i have some hints into this issue

my app actually did subscribe with the key in action[3] and action[7] somewhere else

this.postRef = db.object('/Categories/0'/' + navParam.get('key'));
this.postSub = this.postRef.valueChanges().subscribe(post => {
  doSomething();
})

as long as i am still subscribing, those order would be messed
but once i unsubscribe it, the returned order are perfect

@jamesdaniels
Copy link
Member

Hmmm, interesting. I'll keep an eye out for that.

@kkbear1985
Copy link
Author

confirm fixed, thank you very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants