Meteor pagination crashing the browser

I created an infinite scroll pagination in my app using parameter passed sub/pub method and also use limit and skip inside my publications. but when it taking more than 1000 records the app is getting slow and when it comes to 31000 records the app crashing the browser(as per the query, limit is 10 and skip is 0 but the date range will calculate this 31000 records and when i checked my websockets calls i found that this skip and limit not working it takes all records). the total count of the collection
here is my pub/sub code

Meteor.publish(‘posts’, function (fromDate,toDate,limit) {

const user = Meteor.user();

if (!user) throw new Meteor.Error('not-authorized');

return Parcels.find(
  {
    clientId: user.profile.clientId,
    createdAt:{
      $lte:new Date(toDate),
      $gte:new Date(fromDate)
    }
  }, 
  {
  fields: {
    postroomBarcode: 0,
    recipientSignature: 0,
    owner: 0,
    deliveredByOwner: 0,
    clientId: 0,
  },
  limit:limit,
  skip: limit > 10 ? limit - 10 : 0,
  sort: { createdAt: -1 }
  
});

});

const postsSub = Meteor.subscribe(‘posts’,fromDate.get(),toDate.get(),subscriptionLimit.get()).ready();

The publication will keep all the records sent to the client in minimongo. So even you are displaying less with limits, minimongo is still keeping all records in the client

In these cases, we use methods instead of publications

2 Likes

@rjdavid thank you but how to implement the method without subscription, the data access from server to cleint is possible through subscribe/publication only.

What is limiting you to only use subscription and not a method? In Meteor, you have the option to use either depending on your use case

In our case, everytime the trigger is hit near the bottom of the page, the next set of documents are queried through a method and then appended on the existing records in the client.

1 Like

@rjdavid currently i am using both, method and subscription, first subscribe the data with filter a client id and then using a method with other search parameters , the database is very large and performance is very poor, thats why i changed the publication to pass more parameters and subscribe a minimum amount of data on initial load and load more when triggering the load more button

I don’t know what more I can tell you. If I’m in your place, I will stop using publication for this use case

1 Like

Are you saying this server side code returns all the records despite what’s set on limit and skip? Can you confirm that with debug?

1 Like

@rjdavid @ignl Thanks, i found the reason, the pub/sub method is crashing the browser, when i tried to navigate to other page, it takes too much time for unsubscribe the data. anyway i planned to change the pub/sub method and use an api application for handle this huge data.