活动清单ala SO

时间:2009-10-21 07:04:52

标签: database database-design data-modeling

我们正在为我们的应用程序构建一组功能。其中一个是SO上最近的用户活动列表。我在寻找为这些活动设计表格的最佳方法时遇到了一些问题。

目前,我们有一个包含以下列的活动表

UserId (Id of the user the activity is for)
Type (Type of activity - i.e. PostedInForum, RepliedInForum, WroteOnWall - it's a tinyint with values taken from an enumerator in C#)
TargetObjectId  (An id of the target of the activity. For PostedInForum this will be the Post ID, for WroteOnWall this will be the ID of the User whose wall was written on)
CreatedAtUtc (Creationdate)

我的问题是TargetObjectId列感觉不对。它是一个软链接 - 没有外键,只有关于Type的知识告诉你这个列真正包含的内容。

你们是否有关于存储用户活动列表的备用/更好方式的建议?

我还应该提到该网站将是多语言的,因此您应该能够以多种语言查看活动列表 - 这就是为什么我们没有选择将活动文本/ html放在表格中的原因

由于

2 个答案:

答案 0 :(得分:1)

您可以将所有内容放入带有鉴别器列的单个表中,然后只放置select top 20 ... from ... order by CreatedAtUtc desc

或者,如果您在不同的表中存储不同类型的内容,您可以尝试类似的方法(不确定确切的语法):

select top 20 from (
    select top 20 ID, CreatedAtUtc, 'PostedToForum' from ForumPosts order by CreatedAtUtc
    union all
    select top 20 ID, CreatedAtUtc, 'WroteOnWalll' from WallPosts order by CreatedAtUtc) t
order by t.CreatedAtUtc desc

答案 1 :(得分:0)

您可能需要查看http://activitystrea.ms/以获取灵感,尤其是架构定义。如果你看一下那个规范,你会发现还有“目标”对象的概念。我最近做了一些非常相似的事情,但我不得不创建自己的数据库来封装所有活动数据并将数据提供到其中,因为我从不同数据库中的不同数据源收集来自多个应用程序的活动数据。

最高