这是对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>
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()});
}
}
});
}
当我加载或刷新页面时,Chrome的开发人员工具显示大约需要3秒钟。如果我输入,例如1并按Enter键,那么它看起来几秒钟内没有响应,但最后会显示结果。 也许一些建议说不要从集合中返回所有内容,但实际上它不是一个大数据(5k文档,3个简单字段)返回,我也使用Laravel 5和MySQL做了同样的事情,它的工作原理非常顺利,我在Mongodb CLI中尝试了一些查询看起来也不错,那么Meteor的性能问题是什么?