reactive-table icon indicating copy to clipboard operation
reactive-table copied to clipboard

Subscription for pagination

Open khriztianmoreno opened this issue 9 years ago • 26 comments

Currently my collection has about 4 million of documents, I would like to subscribe to the collection but only for every pagination, I mean an initial subscription of 10 documents, then you go to the next page, subscribe to documents 11 to 20. How can I accomplish this?

khriztianmoreno avatar Feb 10 '16 14:02 khriztianmoreno

You can use ReactiveTable.publish on the server to set up a paginated publication that the table can use.

aslagle avatar Feb 11 '16 02:02 aslagle

@aslagle can you please provide more info about how to setup a paginated publications? In your example I see only publications with some exact fields. Should I use Template.instance reactive variable or it is already provided in your package?

I have tried doing this...

ReactiveTable.publish(Places, {archive: 0})

...and have no results at all.

qrobin avatar Jun 07 '16 19:06 qrobin

You have to pass in a name as the first argument and use it as the collection in the client side table settings.

So ReactiveTable.publish('places', Places, {archive: 0}), and then the collection in the table settings would be "places". You do have to specify a list of fields on the client when you use this - it can't automatically get them from the collection.

aslagle avatar Jun 08 '16 00:06 aslagle

@aslagle have done like you said and it works, thank you for reply without delay.

But now I get another issue with that subscription — when I load exactly that page with table (Places table), it works fine. But if I go to another route and come back to Places (or just come to route with Places from any other route), the table doesn't load.

Here is some DDP subscriptions log, if I can say so.

scr 2016-06-08 at 04 45 43

I would be happy give you more info, if you need. Please, can you suggest what can cause this behavior.

upd Also will be very useful to know which method can I call to check if subscriptions are ready. I would like to display a spinner while server is working after sorting, filtering and other actions that cause publication change. Template.subscriptionsReady() is not working this time.

qrobin avatar Jun 08 '16 01:06 qrobin

It looks like the table is loading when you go back to the places route, but then it's unsubscribing for some reason. It's possible there's a bug in the reactive-table subscription code that's making it unsubscribe, but I think it's more likely the template is getting destroyed. Maybe the blaze inspector would show that. Which router are you using?

For checking if the subscriptions are ready, you can pass in a ready ReactiveVar in the table settings that's set to false, and it will change to true when the initial subscription is ready.

aslagle avatar Jun 09 '16 01:06 aslagle

No, Template is not destroing. I have removed {{#if ready}} inside reactive-table.html and table is rendering, but without any data.

So there is something wrong with subscription, I suppose. I tried to check your js code, but it is to hard for me to understand all it's features.

qrobin avatar Jun 09 '16 01:06 qrobin

In that case, I would guess something's going wrong in the onReady function at line 44 of reactive-table.js, but I'm not sure what it could be.

aslagle avatar Jun 09 '16 01:06 aslagle

By the way, I tried to comment out all the code with stop(), but behavior didn't change at all. I thought that it will keep data in minimongo, but it appears and in 100ms dissapears from minimongo. image image

qrobin avatar Jun 09 '16 01:06 qrobin

Would you like to take a look what is going on? I can share my localhost via ngrok

qrobin avatar Jun 09 '16 01:06 qrobin

Sure, I can take a look.

aslagle avatar Jun 09 '16 01:06 aslagle

One moment

qrobin avatar Jun 09 '16 01:06 qrobin

I didn't minify all the code, maybe it will be useful for you. Here we go

qrobin avatar Jun 09 '16 01:06 qrobin

Just refresh page to let the data appear again

qrobin avatar Jun 09 '16 01:06 qrobin

Could you try changing this line https://github.com/aslagle/reactive-table/blob/master/lib/reactive_table.js#L70 to {onReady: onReady, onStop: onError}.

I see the meteor documentation has onStop.. I wonder if that changed or I just had it wrong the whole time.

aslagle avatar Jun 09 '16 01:06 aslagle

Done.

I also uncommented all code that I have commented before.

qrobin avatar Jun 09 '16 01:06 qrobin

Now your app is crashing :(

aslagle avatar Jun 09 '16 01:06 aslagle

Yep sorry, my fall, just fixed

qrobin avatar Jun 09 '16 01:06 qrobin

Okay, I've set break points every place reactive-table stops a subscription and it's not any of them. There must be something else that's stopping the subscription.

aslagle avatar Jun 09 '16 02:06 aslagle

In my code, you mean?

qrobin avatar Jun 09 '16 02:06 qrobin

Or in another package

aslagle avatar Jun 09 '16 02:06 aslagle

hm okay, so there is no problem with your package, as I understand. So thank you for your time. Anyway it is a great package, I choose it from 3 another as the best worker with big collections.

I will keep searching, and let you know about results.. Thank you, Amy and have a nice day 👍

qrobin avatar Jun 09 '16 02:06 qrobin

As far as I can tell this is getting triggered by flow router calling Tracker.invalidate, but I'm not familiar enough with flow router to know what's going on. Hope you can figure it out :)

aslagle avatar Jun 09 '16 02:06 aslagle

Yes, Amy, you are right. It was FlowRouter. Not sure, what exactly cause this behavior, but changing FlowRouter.go() to BlazeLayout.render() fix it.

qrobin avatar Jun 09 '16 02:06 qrobin

Also one more little question — empty collections in minimongo don't go away while I am walking across the app. Can it cause any perfomance issues if their amount will grow (without refreshing all app)?

image

qrobin avatar Jun 09 '16 03:06 qrobin

That's a good question, I don't know what MiniMongo does with the empty collections internally so I'm not sure if it could be a problem. I don't think there's a way to remove them, but if there is, let me know.

aslagle avatar Jun 09 '16 03:06 aslagle

Found how to fix my problem by calling FlowRouter.reload(); after FlowRouter.go();, works fine.

qrobin avatar Jun 14 '16 00:06 qrobin