0

I'm making a meteor js web app that presents the client an html range slider tied to a session variable.

I want the server to only publish data with values less than the current value of the slider with data sorted from newest to oldest. I have a lot of database entries (2000+). If I publish everything within the max of slider my browsers too slow. If I limit the publish to 100 entries or so, I miss out on a lot of data with small values (which happen to be older) when I bring the slider down.

What are the best practices for trying to be scalable (not sending too much data to the client)? Is a reactive publish function the key (using onchange with the slider value as the key)? That sounds like a lot of server round trips. Help!

zigo
  • 159
  • 1
  • 10
  • Regarding your question about reactive subscribing based on a client session variable: it's definitely possible. Here's an example for your particular case: Deps.autorun(function () { Meteor.subscribe("yourCL", selectorArgs, Number(Session.get('yourSessVar'))); }); The meteor documentation seems to show a new method called "Tracker.autorun"; however I haven't used it. It claims to skip a wasteful unsubscribe/resubscribe – Adam Oct 23 '14 at 18:25
  • I understand the subscribe part of it. My publish function seems to rerun every time that session variable changes (I log the variable via the server). My publish just doesn't send a new subset of the database when I want to... – zigo Oct 23 '14 at 22:00
  • 1
    Without code, it's hard to take a guess. Would a read over [how publish/subscribe works](http://stackoverflow.com/questions/19826804/understanding-meteor-publish-subscribe) help? – Dan Dascalescu Oct 23 '14 at 22:04

1 Answers1

1

Would pagination be acceptable from a UX standpoint? If so, there are packages that may help, for instance alethes:pages.

Otherwise, Adam is on the right track by suggesting to use Tracker.autorun (Tracker has replaced Deps).

As with any other publication, make sure your publish function only returns the fields that you need on the client, in order to minimize the data transferred and the memory consumption.

Community
  • 1
  • 1
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • I want to publish more entries to the client if the user chooses to see more. I'd rather not initially flood the client with everything. I'm not sure if I necessarily need pages to do that. – zigo Oct 23 '14 at 22:01