Meteor: display data - slow client, fast server?

Meteor: display data - slow client, fast server?,meteor,Meteor,Edit - Solved My meteor app is used about about 20 people my office. Basically it's a glorified to-do-list. Managers add projects, and then adds tasks for each project, and then assigns them to employees. Employees see a list of the tasks assigned to them. When a manager posts a new task, it takes a very long time to show up in their own task-list, but shows up near instantaneously for other people (employers or other managers). A manager's project template looks something like: HTML File:

Edit - Solved

My meteor app is used about about 20 people my office. Basically it's a glorified to-do-list. Managers add projects, and then adds tasks for each project, and then assigns them to employees. Employees see a list of the tasks assigned to them.

When a manager posts a new task, it takes a very long time to show up in their own task-list, but shows up near instantaneously for other people (employers or other managers).

A manager's project template looks something like:

HTML File:

<template name="project">
  <input type="button" class="create-task" value="New">
  {{#each tasks}}
    {{> task}}
  {{/each}}
</template>

app.js File:

var createTask = function (projectID) {
  ### a bunch of code that I don't think is relevant to the problem
  ### tasks are fairly complicated but it shouldn't matter
  Tasks.insert({projectID: projectID})
}

if (Meteor.isClient) {
  Template.project.tasks = function () {
    return Tasks.find({projectID: this._id})
  };

  Template.project.events = {
    'click .create-task': function () {
      createTask(this._id)
    }
  }
}

When a manager creates a task, it rerenders the entire tasklist, and it takes about 2 seconds per-task. (tasks are fairly complicated and I need to streamline them, but that's another story). Other employees (and other managers) looking at the same tasklist have the new task appear in about 2 seconds. But for the manager, it takes 10-30 seconds to rerender all of the existing tasks, and it locks up the webpage in the meantime.

I assume I want to somehow insert documents on the server side instead of the client? Is there a proper way to do that?

Edit: (Some additional information - this is somewhat simplified but I believe contains all the relevant pieces)

There are three collections, which are essentially in a hierarchy - Projects, Tasks, and Comments.

Projects contain {name, create_date}
Tasks contain {projectID, name, description, create_date}
Comments contain {projectID, taskID, author, text, create_date, status}

Comment statuses can be "new", "finished", or "approved".

The database is not that large, and displaying all the raw data takes a few seconds. What takes a while is displaying a lot of conditional information. Depending on whether comments are new/approved/finished, they change color and/or are hidden from view.

Managers see a list of projects, and next to each Project, the number of "new", "finished", and "approved" comments associated with that Project. This is generated by something like:

Template.projectMenuItem.newCommentsLength = function () {
  return Comments.find({projectID: this._id, status="new"}).count()
}

Tasks are also shown in a list view, that shows the number of new/finished/approved comments.

There are some other conditional display items. End result is that displaying a Task, even if the list form (without also displaying comments), it ends up taking about 2 seconds for each task template to render. If I remove the conditional-display-items, it renders near instantly.

EDIT - SOLVED: I moved the "createTask" function under "Meteor.methods" in the server code, and then called it from the client. Now adding a new task takes 2 seconds instead of 20-30. I'm still not sure why creating the document client-side was causing it to re-render all the tasks but it seemed like something that should be run server side anyway.


#1

Is your database large? Is autopublish on?

#2

Autopublish is off, although the single largest collection is always published because it interacts with lots of other collections. I'm not sure how big the database is (the "db" folder in .meteor is about 1 gb, but compresses down to 18 mb somehow when I make a zip file). Figuring out how to streamline the database is another problem I'm working on, but even in its current (clunky) state, the fact that something takes 2 seconds for one person but 20 seconds for another person seems odd.

#3

I can't immediately explain the difference in rendering times but without knowing more, this smells like a "publications are too large" problem. Without changing your code, what happens if you run with a clean/small DB?

#4

It's definitely much faster when the database is fresh.

#5

A little more info - all of the publications get loaded in a couple seconds. What seems to take a long time is displaying a lot of conditional information. (accidentally posted too early, working on a better description now)