My app released yesterday and I need help optimizing something


#1

Press release, because why not

This app is using Ionic/Angular on Meteor 1.2.

The home screen uses infinite-scrolling to retrieve documents (20 at a time). Originally I used a publication for this, but found a meteor method provided a smoother experience. However, there are two fields on this document that do need to be reactive. My current solution is to keep an array of the retrieved document ids in an array client-side, which is reactively supplied to a subscription so that I have access to those fields as they change.

The problem is this publication re-runs each time the array of document ids is altered, and it has to re-find the documents it was already monitoring (using $in). So as the user scrolls further and further, the publication is taking longer and longer. The release went really smoothly, but twice a user just kept scrolling and scrolling and the CPU spiked really hard and it started taking over a full second to be ready.

Can I subscribe to the same publication more than once so that it creates a new observer for each page? Is this advisable?

edit: please let me know what I can do to get some help on this


#2

A few ideas:

  • pre-load the next set of documents (retrieve a larger set at a time)
  • cache the document ids server-side and only retrieve documents that are required
  • poll for changes instead of using a publication

#3

Do you also remove invisible items form that array at the top when the user scrolls down? Or does it get only longer and longer?


#4

HI @bmanturner,

When you want data to be reactive, publication and subscription is best option.
Why do you have to send retrieved id as array to server again through subscription?
As I understood the problem, you need an reactive infinite scroll. Consider this solution:

  1. Pass only count to sub as parameter.
  2. Subscription code placed Tracker.autorun()

When you subscribe to same sub in autorun but with different parameters, previous subscription will be unsudscribed and new subscription will run. Its totally fine to subscribe to same publication . Also autorun will unsubscribe the current active sub, whenever neccess Previous sub documents will be merged with newer ones but with a time gap to avoid flicker.ary, so you dont need to send array of ids again to pub.

For detailed explanation:
https://codebrahma.com/reactive-subscriptions-in-meteor/
https://codebrahma.com/meteor-publications-and-subscriptions/