【发布时间】:2013-12-20 10:08:50
【问题描述】:
正如 Abigail Watson 在thisgoogle 小组讨论中解释的那样,数据库抖动是 Meteor.js 中发生的一种现象,但没有详细说明。似乎出现了package 来解决这个问题。
所以,我的问题是,Meteor.js 中的“数据库抖动”是什么,以及在检查时它如何影响我,例如Deps.autorun() 中的 Meteor.user()?
编辑:我添加了一个让我头疼的代码示例,我认为这是由“数据库抖动”引起的。当用户登录时,Meteor.user() 中的console.logs 通常会运行几次,与注销console.logs 相同。在“userLoggedOut”内部,我正在重置 Meteor.user().profile.setAvailable 布尔值,有时这会让我陷入一个永恒的循环,因为 if(Meteor.user()) 会再次运行。这当然也可能是我做错了什么.. :)
我在使用这段代码时遇到了这个问题:
var lastUserId;
Deps.autorun(function () {
if(Meteor.user()) {
lastUserId = Meteor.user()._id;
console.log("USER LOGGED IN WITH USER ID", lastUserId);
if (Meteor.user().profile.setAvailable) {
Meteor.call('setAvailable',
{
options: Meteor.user()
.profile
.someDataThatShouldBeSetAvailable
});
}
if (Meteor.user().profile.forceLogOut) {
Meteor.call('resetForceLogOut',
{
userId: Meteor.user()._id
});
window.location.reload();
}
} else {
if (lastUserId) {
console.log("LOGOUT: We should do something
with this id", lastUserId);
Meteor.call('userLoggedOut',
{
userId: lastUserId
});
} else {
console.log("We don't have any lastUserId, the page
has probably been refreshed");
}
}
});
【问题讨论】:
-
您的问题到底是什么?你遇到过这个问题吗?你想做什么?如果您提供预期结果、实际结果和一些重现实际结果的代码,您的问题会更容易回答。