简体   繁体   English

Meteor.js发布和订阅2

[英]Meteor.js Publishing and Subscribing 2

I had another recent question on the same topic (for posterity: Meteor.js Publishing and Subscribing? ). 我最近对同一主题有另一个问题(后代: Meteor.js Publishing and Subscribing? )。

I have a test Meteor site. 我有一个测试流星网站。 I have the following in a file on the root directory: 我在根目录下的文件中具有以下内容:

/** 
* Models
*/

Posts = new Meteor.Collection('posts');


posts = Posts;

if (Meteor.isClient) {

    Meteor.subscribe('posts');

}

if (Meteor.isServer) {

    Meteor.publish('posts', function() {
        return posts.find({}, {time:-1, limit: 100});
   });


    posts.allow({

        insert: function (document) {
            return true;
        },
        update: function () {
            return false;
        },
        remove: function () {
            return false;
        },

    });

}

What happened was that I made an edit, and it stopped working (on the dev. server: localhost:3000). 发生的事情是我进行了编辑,但它停止了工作(在开发服务器上:localhost:3000)。 I reverted the edit back, but I guess something changed, because it no longer works. 我恢复了编辑,但是我猜有些改变了,因为它不再起作用了。

The client does have access to the Collection (the list of posts loads) so that isn't the issue. 客户确实有权访问集合(帖子列表),所以这不是问题。

The issue is that the second the client submits a post, it appears for a second on the list then disappears. 问题是客户提交帖子的秒数,列表中出现的秒数,然后消失。

It seems similar behavior to when the client doesn't have publishing rights, but as you can see above I have given it. 这似乎与客户端没有发布权时的行为类似,但是正如您在上面看到的,我已经给出了。

When I go to the JS Console in Chrome, no "access denied" or error comes up. 当我在Chrome中转到JS控制台时,没有出现“拒绝访问”或错误的提示。

When I try 'adding a post' from the Console, the same sort of behavior happens. 当我尝试从控制台“添加帖子”时,会发生相同的行为。 A flicker, then it's gone. 闪烁,然后消失了。

What's going on? 这是怎么回事? Is it just a weird Meteor glitch? 仅仅是奇怪的流星故障吗? Any help appreciated. 任何帮助表示赞赏。

EDIT 编辑

OK, clearly some sort of internal Meteor glitch; 好吧,显然是某种内部流星故障。 a "meteor reset" fixed the problem with NO CHANGE in the code itself. “流星重置”解决了代码本身没有更改的问题。

So I guess problem solved! 所以我想问题解决了!

EDIT 2 编辑2

Noooo. Problem not solved. 问题没有解决。 It appeared again. 它又出现了。

It seems to reject them once the number of posts reaches a certain threshold, which leads me to believe it has something to do with the "limit". 一旦帖子数达到一定阈值,似乎就拒绝了它们,这使我相信这与“限制”有关。

Any help? 有什么帮助吗?

Suppose your client has 100 posts in its local cache. 假设您的客户在其本地缓存中有100个帖子。 Then when the client inserts a new post, it's inserted directly into the client cache (so it does now contain 101 posts) and in the background it's sent to the server. 然后,当客户端插入新帖子时,它将直接插入到客户端缓存中(因此现在确实包含101个帖子),并在后台将其发送到服务器。 The server inserts it into the real database, and then tells the client to remove one of it's cached posts, since it's supposed to only store 100 posts in it's cache. 服务器将其插入到真实数据库中,然后告诉客户端删除其缓存的帖子之一,因为它应该仅在缓存中存储100个帖子。 This is probably what's happening to you. 这可能是您正在发生的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM