流星反应数据查询带有用户名和图片的注释 [英] Meteor Reactive Data Query for Comments with Usernames and Pictures

查看:206
本文介绍了流星反应数据查询带有用户名和图片的注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个大型应用程序中实现评论系统,并且始终遇到交叉反应和发布的问题.

I am trying to implement a commenting system in a huge app and always run in the problem about cross reactiveness and publications.

具体问题:

当用户发表评论时,我想显示该用户的姓名和个人资料图片.注释在一个集合中,名称和图片在另一个集合中.

When a user writes a comment, I want to show the user's name and a profile picture. The comments are in one collection, the names and pictures in another.

当我为该页面上的每个评论以及ID在服务器端此页面的评论中的每个用户进行订阅时,当添加新评论时,该应用程序不会更新客户端上可用的用户,因为"joins"在服务器上是非激活的.

When I make a subscription for every comment on this page and for every user whose id is in a comment of this page serversided, the app does not update the users available on the client when a new comment is added because "joins" are nonteactive on the server.

当我在客户端上执行此操作时,我必须一直取消订阅并重新订阅,添加了新评论,并且负担越来越重.

When I do that on the client, i have to unsubscribe and resubscribe all the time, a new comment is added and the load gets higher.

在流星中实施这种系统的最佳实践是什么?我该如何解决这个问题而又不会大量出版?

what is the best practise of implementing such a system in meteor? how can i get around that problem without a huge overpublishing?

推荐答案

由于尚未正式支持加入,因此社区中的所有解决方案都

As there is not official support for joins yet,among all the solutions out there in community

我找到了 https://github.com/englue/meteor-publish-composite该软件包非常有帮助,我正在我的应用程序中使用它.

I found https://github.com/englue/meteor-publish-composite this package very helpful and I'm using it in my app.

此示例非常适合您的要求

This example perfectly suits your requirement https://github.com/englue/meteor-publish-composite#example-1-a-publication-that-takes-no-arguments

Meteor.publishComposite('topTenPosts', {
    find: function() {
        // Find top ten highest scoring posts
        return Posts.find({}, { sort: { score: -1 }, limit: 10 });
    },
    children: [
        {
            find: function(post) {
                // Find post author. Even though we only want to return
                // one record here, we use "find" instead of "findOne"
                // since this function should return a cursor.
                return Meteor.users.find(
                    { _id: post.authorId },
                    { limit: 1, fields: { profile: 1 } });
            }
        },
        {
            find: function(post) {
                // Find top two comments on post
                return Comments.find(
                    { postId: post._id },
                    { sort: { score: -1 }, limit: 2 });
            },
            children: [
                {
                    find: function(comment, post) {
                        // Find user that authored comment.
                        return Meteor.users.find(
                            { _id: comment.authorId },
                            { limit: 1, fields: { profile: 1 } });
                    }
                }
            ]
        }
    ]
});

//客户端

Meteor.subscribe('topTenPosts');

最主要的是它是反应性

这篇关于流星反应数据查询带有用户名和图片的注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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