Firebase data load slow on iOS

ios
firebase

#1

Hi,

I have created an app using the tns-template-master-detail-ng template. All works great until I switch from firebase.addValueEventListener() to firebase.query() when iOS grind to a halt with more than 20 records. Android is near instantaneous with any number of records but iOS takes around 1:30 to load 100 records.

I want to use .query() as the whole dataset will be in excess of 25k records and using this with .addValueEventListener() gives a memory overflow. Also, as well as limiting the records loaded each time, I will need to have filtering and sorting.

firebase.query(
	onQueryEvent,
	`/${path}`,
	{
		orderBy: {
			type: firebase.QueryOrderByType.CHILD,
			value: "loggedAt" // mandatory when type is 'child'
		},
		limit: {
			type: firebase.QueryLimitType.LAST,
			value: 500
		}
	}
);

const onQueryEvent = (result: any) => {
	// note that the query returns 1 match at a time
	// in the order specified in the query
	if (!result.error) {
		this._ngZone.run(() => {
			// console.log("Event type: " + result.type);
			// console.log("Key: " + result.key);
			// console.log("Value: " + JSON.stringify(result.value));
			this._requests.unshift(new Request(result.value));
			const results = this._requests;
			observer.next(results);
		});
	}
};

This is based on based on nativescript-plugin-firebase/docs

Any pointers as to where I am going wrong?

David


#2

I have made it work by creating a year index with an array that just lists the IDs, thus ensuring that there is less data to be loaded. I then loop these to get the actual records. I see this is a better pattern but I think my data volumes are still low so I would appreciate if anyone can tell me where I am going wrong with the straight .query() call.

Thanks,

David