reactive-table
reactive-table copied to clipboard
Too long Server-side Pagination initial load
I have a collection with 40K records and have configured Server-side Pagination:
SERVER:
collectionData = ->
if @userId
allRecordsCollection
else
[]
ReactiveTable.publish 'allRecords', collectionData
CLIENT:
+reactiveTable collection="allRecords" settings=settings
As a result initial table load takes around 7-8 seconds on production server and generates table with 2K pages. When initial load finished, navigation by pages works quickly and Filtering also works quickly. When Filter is cleared table load time is again 7-8 seconds.
Questions:
- Why Server-side Paginations takes so much time? It loads whole collection from MongoDB?
- Maybe it is possible to speed up somehow table load in following cases?:
- If it is initial load
- If Filter was applied and than cleared
In fact I don't need such a huge table with thousands of pages when no filter is applied. It will be even enough to show initially empty table but with filter input shown. And only after any search query is entered in filter field table will be populated with data.
Any comments?
I'm having the same problem. Even with the ReactiveTable.publish the initial load takes so much time around of 5 or 6 seconds.
Hey @geremora
This problem appears because full collection is pulled from MongoDB (either by Client, or Server (with Server Side Pagination). But in fact no one needs full collection with hundreds of thousands records. Anyway you will filter the table to find subset of records.
So, I have found solution how to avoid such a long wait time and optimize overall performance. Server Side Pagination is not needed for that.
I have added custom filter fields for columns in the table which I use most often for filtering like
.input-group
span.input-group-addon Search request
input.searchRequest
And only when user enters some text in this search field, I transform it to Mongo request format and use conditional Meteor subscription.
Client: (textRequestField if reactiveVar that is changed when .searchRequest input is changed)
records: ->
matchConditions["filedTitle"] = textRequestField.get()
Meteor.subscribe "collectionRecords", matchConditions
return Collection.find matchConditions
+reactiveTable collection=allMegaindexVisibility settings=settings
Server
Meteor.publish "collectionRecords", (matchConditions) ->
check matchConditions, Object
Collection.find matchConditions
,
limit: 300
With such config you will have always not more than 300 records in your table that will be more than enough for further filtering using reactive-table functionality.
Hope this will help.
Thanks @naho2081!
I thought that the ReactiveTable.publish not pull all of records :(
Your solution looks good I'm going in that way.
I had a same problem. the problem is issue with
fullCursor.observeChanges
try to disable observeChanges
by using the followed setting:
{
disablePageCountReactivity: true
}
also you can add disableRowReactivity: true
to the setting
full publish code would be like this:
ReactiveTable.publish("publishName", collection, {}, {
disablePageCountReactivity: true,
disableRowReactivity: true
});