实现类似Twitter的跟随者系统的好方法? [英] Good way of implementing a twitter-like follower system?

查看:126
本文介绍了实现类似Twitter的跟随者系统的好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个类似twitter的追随者系统(用户可以关注另一个)。我对存储关注者关系的好方法感到困惑。我使用的是JDO(在谷歌应用程序引擎上)。

I'm trying to create a twitter-like follower system (users can follow one another). I'm confused about a good way to store the follower relationships. I'm using JDO (on google app engine).

首先想到的是为追随者保留一个Set,以及您正在追踪的那个人。例如:

The first thing that comes to mind is to keep a Set for followers, and the ppl you are following. Something like:

class User {

   private String mUsername;

   private Set<String> mFollowers;

   private Set<String> mFollowees;
}

我担心这些集合增长到10,000+在他们的条目。查看用户的页面将是一个常见的操作,我不希望每次需要生成用户信息时都需要加载整个集合。我一次只能显示50个关注者,所以加载整个集合是没有意义的。

I'm worried about what happens when those sets grow to have like 10,000+ entries in them. Viewing a user's page is going to be a common operation, and I'd hate to have to load the entire Sets every time my API needs to generate user info. I'm only going to be showing 50 followers at a time anyway, so it makes no sense to load the entire Set.

另一种可能是使用中间类来存储关系,这样它们就不会绑定到用户对象。分页应该也很容易(我认为)。例如,每当我想关注用户时,我都会创建这个对象的一个​​实例:

An alternate could be using an intermediate class to store relationships, this way they are not bound to the User object. Paging should then also be easy (I think). For example, whenever I want to follow a user, I'd create an instance of this object:

class RelationshipInfo {

    private String mMyUsername;

    private String mUsernameYouAreFollowing;
}

所以当我查看用户的页面时,我可以查询前50个上面的记录给出了用户的ID。这是否有任何性能意义?我不确定这是否比上面的第一个选项更好。这种方式需要更多的访问数据存储。

so when I view a user's page, I could query for the first 50 such records above given the user's id. Does that make any performance sense? I'm not sure if this is better than the first option above. This way would require more trips to the datastore.

任何想法都会很棒,

谢谢

推荐答案

Brett Slatkin的在App Engine上构建可扩展,复杂的应用程序来自去年的Google I / O实际上使用类似Twitter的应用程序作为示例。除此之外,这是一个很好的话题,我强烈推荐它,即使它没有特别涉及到你要求的内容。

Brett Slatkin's Building Scalable, Complex Apps on App Engine talk from last year's Google I/O actually uses a Twitter-like application as its example. Even aside from that, it's a great talk and I highly recommend it even if it didn't relate specifically to what you're asking.

另外,您可能想要请查看 Jaiku ,这是一款基于App Engine构建的开源Twitter类应用程序。

Also, you may want to check out Jaiku, an open-source Twitter-like application built on App Engine.

这篇关于实现类似Twitter的跟随者系统的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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