Skip to content
This repository has been archived by the owner on Jun 24, 2023. It is now read-only.

Collection loads slow #11

Open
dennismonsewicz opened this issue Mar 31, 2014 · 0 comments
Open

Collection loads slow #11

dennismonsewicz opened this issue Mar 31, 2014 · 0 comments

Comments

@dennismonsewicz
Copy link

I am limiting my collection to 500 records, but when I use:

Meteor.subscribe('jobs', function onReady(){
  Session.set('jobsLoaded', true);
});

Template[templateName].helpers({
  selected: function(){
    return Session.get('perPage');
  },
  jobsReady: function() {
    return Session.equals('jobsLoaded', true);
  }
});

Template[templateName].jobs = function() {
  if(Session.get('jobsLoaded')) {
    var cursor, options = {};

    if(Session.get('currentIndustry')) {
      options.industry = Session.get('currentIndustry');
    }

    if(Session.get('currentMapArea')) {
      city = Cities.findOne(Session.get('currentMapArea'));
      address = city.city.toProperCase() + ", " + city.state;
      options.address = address;
    }

    cursor = Jobs.find(options, {sort: { dateacquired: -1 }, limit: Session.get('perPage')});

    return Pagination.collection(cursor.fetch(), {perPage: Session.get('perPage'), currentPage: Session.get('page') || 1})
  }
}

It takes a while for the pagination to render to the user. Here is my template:

<template name="jobs">
  <div class="col-md-12">
    {{#with jobsReady}}
      <ul class="list-group fadeout" id="jobs">
        {{#each jobs}}
          {{> job}}
        {{/each}}
      </ul>
    {{else}}
      {{> spinner}}
    {{/with}}
  </div>

  <div class="col-md-12 col-sm-12">
    <div class="row fadeout">
      <div class="col-md-2 col-sm-2">
        {{#with jobsReady}}
          <select id="perPage" class="selectpicker select-block" _val="{{selected}}">
            <option value="10">10 Per Page</option>
            <option value="25">25 Per Page</option>
            <option value="50">50 Per Page</option>
            <option value="100">100 Per Page</option>
          </select>
        {{/with}}
      </div>

      <div class="col-md-10 col-sm-10">
        {{{pagination}}}
      </div>
    </div>
  </div>
</template>

<template name="job">
  <li data-id="{{ _id }}">
    <span class="dateacquired pull-right"><em>added: {{{ timeago dateacquired }}}</em></span>
    <span class="jobTitle">
      <a href="{{url}}" target="_blank">{{title}}</a>
    </span>
    <span class="company"><em>{{company}}</em></span>
    <span class="">{{address}}</span>
  </li>
</template>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant