Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测试中的表现很糟糕,在Meteor中正常吗?_Meteor_Meteor Blaze - Fatal编程技术网

测试中的表现很糟糕,在Meteor中正常吗?

测试中的表现很糟糕,在Meteor中正常吗?,meteor,meteor-blaze,Meteor,Meteor Blaze,下面是对Meteor 1.2.1性能的一个小测试 performance.html <head> <title>performance</title> </head> <body> <br><br> <form class="search-form"> <input type="text" name="keyword" placeholder="Enter a keywor

下面是对Meteor 1.2.1性能的一个小测试

performance.html

<head>
  <title>performance</title>
</head>

<body>
  <br><br>
  <form class="search-form">
    <input type="text" name="keyword" placeholder="Enter a keyword to search">
  </form>
  <br>
  {{> items}}
</body>

<template name="items">
  <table>
    <thead></thead>
    <tbody>
      {{#each items}}
        <tr>
          <td>{{first}}</td>
          <td>{{second}}</td>
          <td>{{third}}</td>
        </tr>
      {{/each}}
    </tbody>
  </table>
</template>

演出



{{>项目} {{{#每项} {{first}} {{second}} {{third}} {{/每个}}
performance.js

Items = new Mongo.Collection('items');

if (Meteor.isClient) {
  Template.items.helpers({
    items: function () {
      if (Session.get('input')) {
        var keyword = Session.get('input');
        var regex = new RegExp(keyword, "i");
        return Items.find({$or: [{first: regex}, {second: regex}, {third: regex}]});
      } else {
         return Items.find();
      }
    }
  });
  Template.body.events({
    "submit .search-form": function (events) {
      events.preventDefault();

      var input = events.target.keyword.value;
      Session.set('input', input);
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
    if (Items.find().count() < 5000) {
      for (var i = 1; i <= 5000; i++) {
        Items.insert({first: 'first_' + i, second: 'second_' + i, third: 'third_' + i, createdAt: new Date()});
      }
    }
  });
}
Items=newmongo.Collection('Items');
if(Meteor.isClient){
Template.items.helpers({
项目:功能(){
if(Session.get('input')){
var关键字=Session.get('input');
var regex=new RegExp(关键字“i”);
returnitems.find({$or:[{first:regex},{second:regex},{third:regex}]});
}否则{
返回Items.find();
}
}
});
Template.body.events({
“提交.搜索表单”:功能(事件){
events.preventDefault();
var输入=events.target.keyword.value;
Session.set('input',input);
}
});
}
if(Meteor.isServer){
Meteor.startup(函数(){
//启动时在服务器上运行的代码
if(Items.find().count()<5000){

对于(var i=1;i这可能是一些不同的事情……在点击submit之后,在DOM上呈现5000个项目可能会有点费力。您能确认呈现是花费时间还是Mongo regex查询吗?另外,请查看chrome dev tools的网络选项卡,查看客户端和服务器之间对xhr websocket的请求有多大chatter。它可能每隔几秒钟就将完整的5000条记录数据集从服务器传递到客户端。当页面刷新时,它将有大约80个请求,其中一个(不总是那个)将占用大部分时间。当点击搜索时,它看起来无法从开发人员工具中获取信息。奇怪的是,搜索不会在chrome网络选项卡中生成任何事件。在firefox中也是如此。可能它是在minimongo本地完成的。