流星收集提取太慢 [英] meteor collection fetching too slow

查看:124
本文介绍了流星收集提取太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序订阅4个集合(集合是非常小1到20记录每个)。但加载这些集合所需的时间是巨大的。
其中一个只有13条记录,它需要几秒钟来加载其模板。是正常吗? (我仍在测试流星服务器)



这是一个代码示例:



< pre class =lang-js prettyprint-override> Meteor.subscribe('trackedUser',function(){
console.log('finished fetched trackedUser');
Template .users.rendered = function(){
/ *模板的handlign * /


console.log('users template rendered');
}

});

/ *在所有获取后观察地理位置* /
Meteor.subscribe('geolocation',function(){
console.log('finished fetching location');
/ *当插入或删除项目时,忽略集合地理位置和触发器事件* /
query = Geolocation.find({});
query.observeChanges({
added:function (id){
addMarkerToMap(id);
window.map.fitBounds(group.getBounds());
return;
}
});
});
});

这是我的模板

 < template name =users> 
< ul id =item-list>
{{#each trackedUser}}
< li id ={{_ id}}>
< input type =checkboxchecked />
< span>< select name =colorpicker>
{{#each color}}
< option value ={{mColorCode}}{{selected ../mColor mColorCode}}> {{mColorName}}< / option&
{{/ each}}
< / select>
< / span>
< img width =40src =data:image / png; base64,{{mImage}}/>
< span class =name> {{mUsername}}< / span>
< p>< span class =description> {{mDescription}}< / span>< / p&
< / li>
{{/ each}}
< / ul>
< / template>

感谢

解决方案

我能够通过在加载页面时添加一个条件到模板内容为false的条件来解决这个问题,即执行初始同步,并且仅在加载时激活该内容。 p>

之前(服务器发布300个记录的10秒页面加载):

  Template.itemlist.items = function(){
return Item.find({type:'car'},
{sort:{start:-1},
limit:30 });
};

到(服务器发布的3000条记录的2s页面加载):

  Template.itemlist.items = function(){
if(Session.get(active)){
return Item。 find({type:'car'},
{sort:{start:-1},
limit:30});
} else {
return [];
}
};

为了仅在数据加载后激活会话,我添加了:

  Deps.autorun(function(){
Meteor.subscribe(Item,
{
onReady: function(){
Session.set(active,true);
}
});
});


I have an app that subscribes to 4 collections (the collections are very small 1 to 20 records each). But the amount of time it takes to load these collections is huge. One of them is just 13 records, and it takes several seconds to load its template. Is it normal? (I'm still testing on meteor servers)

this is a sample of the code :

Meteor.subscribe('trackedUser', function() {
  console.log('finished fetching trackedUser');
  Template.users.rendered = function() {
   /*handlign of the template*/


    console.log('users template rendered');
  }

  });

    /*observe geolocation after it is all fetched*/
  Meteor.subscribe('geolocation', function() {
    console.log('finished fetching location');
    /* Obseve the Collection geolocation and trigger event when item inserted or removed  */
    query = Geolocation.find({});
    query.observeChanges({
      added: function(id) {
        addMarkerToMap(id);
        window.map.fitBounds(group.getBounds());
        return;
      }
    });
  });
});

And this is my template

<template name="users">
<ul id="item-list">  
   {{#each trackedUser}}
    <li id="{{_id}}"> 
        <input type="checkbox" checked /> 
        <span><select name="colorpicker">
                {{#each color}}
                  <option value="{{mColorCode}}" {{selected ../mColor mColorCode}}>{{mColorName}}</option>
                {{/each}}
              </select>
        </span>
        <img width="40"  src="data:image/png;base64,{{mImage}}" />  
        <span class="name">{{mUsername}}</span>
        <p><span class="description">{{mDescription}}</span></p>  
    </li>  
    {{/each}}
</ul>
</template>

Thanks

解决方案

I was able to solve this issue by adding a condition to the definition of the template content that is false while loading the page, i.e., doing the initial sync, and only activating that content when it was loaded.

Before (10s page load for 300 records being published by the server):

Template.itemlist.items = function () {
    return Item.find({type: 'car'},
                     {sort: {start: -1},
                      limit: 30});
};

To (2s page load for 3000 records published by the server):

Template.itemlist.items = function () {
    if (Session.get("active")) {    
        return Item.find({type: 'car'},
                         {sort: {start: -1},
                          limit: 30});
    } else {
        return [];
    }
};

To "activate" the session only once the data was loaded, I added:

Deps.autorun(function () {
    Meteor.subscribe("Item", 
                     {
                         onReady: function() {
                             Session.set("active", true);
                         }
                     });
});

这篇关于流星收集提取太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆