reactive-table
reactive-table copied to clipboard
Subscription for pagination
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?
You can use ReactiveTable.publish on the server to set up a paginated publication that the table can use.
@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.
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 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.
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.
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.
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.
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.
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.
Would you like to take a look what is going on? I can share my localhost via ngrok
Sure, I can take a look.
One moment
I didn't minify all the code, maybe it will be useful for you. Here we go
Just refresh page to let the data appear again
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.
Done.
I also uncommented all code that I have commented before.
Now your app is crashing :(
Yep sorry, my fall, just fixed
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.
In my code, you mean?
Or in another package
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 👍
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 :)
Yes, Amy, you are right. It was FlowRouter. Not sure, what exactly cause this behavior, but changing FlowRouter.go()
to BlazeLayout.render()
fix it.
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)?
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.
Found how to fix my problem by calling FlowRouter.reload();
after FlowRouter.go();
, works fine.