实施社交活动流的最佳方式是什么? [英] What's the best manner of implementing a social activity stream?

查看:30
本文介绍了实施社交活动流的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很想听听您的意见,哪些是实施社交活动流的最佳方式(Facebook 是最著名的例子).涉及的问题/挑战是:

I'm interested in hearing your opinions in which is the best way of implementing a social activity stream (Facebook is the most famous example). Problems/challenges involved are:

  • 不同类型的活动(发帖、评论......)
  • 不同类型的对象(帖子、评论、照片......)
  • 涉及不同角色的 1-n 个用户(用户 x 回复了用户 y 对用户 Z 帖子的评论")
  • 对同一活动项目的不同看法(您评论了.."与您的朋友 x 评论了"与用户 x 评论了.."=>评论"活动的 3 种表示)

.. 以及更多,特别是如果您将其提升到高度复杂的程度,例如 Facebook 所做的,将多个活动项目合并为一个(用户 x、y 和 z 对该照片发表了评论"

.. and some more, especially if you take it to a high level of sophistication, as Facebook does, for example, combining several activity items into one ("users x, y and z commented on that photo"

对于实现此类系统、数据模型等的最灵活、最有效和最强大的方法的模式、论文等的任何想法或指示,我们将不胜感激.

Any thoughts or pointers on patterns, papers, etc on the most flexible, efficient and powerful approaches to implementing such a system, data model, etc. would be appreciated.

尽管大多数问题都与平台无关,但我很有可能最终在 Ruby on Rails 上实现了这样的系统

Although most of the issues are platform-agnostic, chances are I end up implementing such a system on Ruby on Rails

推荐答案

我已经创建了这样的系统并采用了这种方法:

I have created such system and I took this approach:

包含以下列的数据库表:id、userId、type、data、time.

Database table with the following columns: id, userId, type, data, time.

  • userId 是生成活动的用户
  • type 是活动的类型(即撰写博客文章、添加照片、评论用户照片)
  • data 是一个序列化的对象,包含活动的元数据,您可以在其中放入任何您想要的内容
  • userId is the user who generated the activity
  • type is the type of the activity (i.e. Wrote blog post, added photo, commented on user's photo)
  • data is a serialized object with meta-data for the activity where you can put in whatever you want

这限制了搜索/查找,您可以在提要、用户、时间和活动类型中进行,但在 facebook 类型的活动提要中,这并不是真正的限制.有了正确的表索引,查找快速.

This limits the searches/lookups, you can do in the feeds, to users, time and activity types, but in a facebook-type activity feed, this isn't really limiting. And with correct indices on the table the lookups are fast.

通过这种设计,您必须决定每种类型的事件应该需要哪些元数据.例如,一张新照片的提要活动可能如下所示:

With this design you would have to decide what metadata each type of event should require. For example a feed activity for a new photo could look something like this:

{id:1, userId:1, type:PHOTO, time:2008-10-15 12:00:00, data:{photoId:2089, photoName:A trip to the beach}}

你可以看到,虽然照片的名称肯定存储在其他包含照片的表中,我可以从那里检索名称,但我会在元数据字段中复制名称,因为你没有如果您想要速度,想要对其他数据库表进行任何连接.为了显示来自 50 个不同用户的 200 个不同事件,您需要速度.

You can see that, although the name of the photo most certainly is stored in some other table containing the photos, and I could retrieve the name from there, I will duplicate the name in the metadata field, because you don't want to do any joins on other database tables if you want speed. And in order to display, say 200, different events from 50 different users, you need speed.

然后我有扩展基本 FeedActivity 类的类,用于呈现不同类型的活动条目.事件分组也将在渲染代码中构建,以降低数据库的复杂性.

Then I have classes that extends a basic FeedActivity class for rendering the different types of activity entries. Grouping of events would be built in the rendering code as well, to keep away complexity from the database.

这篇关于实施社交活动流的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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