PHP 新闻源数据库和设计

发布于 2024-09-01 09:44:19 字数 1252 浏览 6 评论 0原文

我正在使用 PHP/MySQL 设计一个类似于 facebook 的新闻源系统。

我以前问过类似的问题,但现在我改变了设计,并且正在寻求反馈。

新闻示例:

User_AUser_B的新专辑发表了评论。

“嘿伙计,照片真漂亮!”

用户_B向[他/她的]个人资料添加了一张新照片

 [显示照片缩略图]

最初,我使用 Obj1:Type1 | 的过多列来实现此目的。对象2:类型2 |等等..

现在,使用几个特殊关键字和参与者/接收者关系来设置设计。我的数据库使用在包含 userid、actionid、receiverid、receiverObjectTypeID 的表上加入的消息表,

这是加入后的精简版本:

News_ID | User_ID |                  Message                   |     Timestamp

  2643       A       %a commented on %o's new %r.                  SomeTimestamp
  2644       B     %a added a new %r to [his/her] profile.         SomeTimestamp
                         

%a = 执行操作的人员的 User_ID

%r = 接收对象

%o = 接收对象的所有者(例如相册的所有者)(如果 %r 是用户,则为 NULL)

问题:

  1. 这是一种智能(高效/可扩展)的方法吗?继续前进?

  2. 如何存储“活动预览”?例如,如果我想显示 User_A 对 User_B 所做的评论(如上所述,以及在 Facebook 的新闻源上)。我考虑过仅使用相关数据的编码副本..例如对评论文本或照片 html 进行 JSON 编码..但这似乎很脆弱(用户可能会在照片仍在其他用户的 feed 中时删除它)

  3. 如何我可以显示如下消息:“User_B 在他的帖子中添加了 4 张新照片 个人资料。”带有照片缩略图?

I'm designing a News Feed system using PHP/MySQL similar to facebook's.

I have asked a similar question before but now I've changed the design and I'm looking for feedback.

Example News:

User_A commented on User_B's new album.

  "Hey man nice pictures!"

User_B added a new Photo to [his/her] profile.

     [show photo thumbnail]

Initially, I implemented this using excessive columns for Obj1:Type1 | Obj2:Type2 | etc..

Now the design is set up using a couple special keywords, and actor/receiver relationships. My database uses a table of messages joined on a table containing userid,actionid,receiverid,receiverObjectTypeID,

Here's a condensed version of what it will look like once joined:

News_ID | User_ID |                  Message                   |     Timestamp

  2643       A       %a commented on %o's new %r.                  SomeTimestamp
  2644       B     %a added a new %r to [his/her] profile.         SomeTimestamp
                         

%a = the User_ID of the person doing the action

%r = the receiving object

%o = the owner of the receiving object (for example the owner of the album) (NULL if %r is a user)

Questions:

  1. Is this a smart (efficient/scalable) way to move forward?

  2. How can I store a "Preview of the event"? For example, if I want to show the comment that User_A made to User_B (like above, and on facebook's news feed). I have considered using an encoded copy of only the relevant data.. for example JSON encoding the comment text or photo html.. but this seems fragile (the user may delete the photo while it's still in another users' feed)

  3. How can I show messages like: "User_B added 4 new photos to his
    profile." with thumbnails of the photos?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

喜爱纠缠 2024-09-08 09:44:19

最近刚刚构建了类似的东西,我建议的一件事是将如何存储数据的想法与性能分开。就我而言,用户需要能够返回并查看任何时间段的新闻,因此 arnorhs 的假设不起作用(无论如何,如果您不需要的话,就没有理由存储 HTML——离开外部格式化)。

我发现我将这些内容存储在几个类中:ActivityTypeActivityActivityType 保存消息的格式(例如您的'%a 对 %o 的新 %r 发表评论')以及指示它是代表实际活动还是对某人的评论else 的活动(所以我知道要链接到哪个对象,参与者的活动或评论的活动的参与者),Activity 存储参与者、受害者、对象的主键、对象的主键注释对象(如果存在)及其发生的时间戳。

这一切都很棒,并且会产生很好的标准化数据。一旦你有六个朋友,速度就会变慢(由于整个事情都是基于位置的,所以性能变得复杂,所以我要查找每个用户距你的距离)。现在每个人都在寻找借口来玩NoSQL存储系统,但这实际上是一个很好的借口。您将必须对数据进行非规范化才能从关系数据库获得良好的性能。由于关系的交叉点多种多样,这些内容很难缓存。考虑将数据存储在 MySQL 中,但从 NoSQL 存储系统中取出数据。

Having built something similar just recently, one thing I would suggest is to separate the idea of how to store the data from performance. In my case, the users need to be able to go back and look at news from any time period, so arnorhs' assumptions don't work (regardless, there's no reason to store HTML if you don't have to-- leave the formatting outside).

What I found was that I store the stuff in a couple of classes, ActivityType and Activity. ActivityType holds the format for the message (like your '%a commented on %o's new %r') and an indicator of whether it represents actual activity or a comment on someone else's activity (so I know which object to link to, the actor's activity or the actor of the activity commented upon) and Activity stores the actor, victim, primary key of the object, a primary key to the commented-upon object if it exists and the timestamp of when it occurred.

Which is all great and results in nicely-normalized data. Which slows to a crawl as soon as you have a half-dozen friends (performance is complicated by the fact the whole thing is location-based so I'm looking up the distance each that user is away from you). Everybody is looking for an excuse to play with NoSQL storage systems now, but this is actually a good one. You're going to have to de-normalize the hell out of the data to get decent performance from a relational database. And the stuff's hard to cache due to the various intersections of relationships. Think about storing the data in MySQL but getting it back out of a NoSQL storage system.

傲影 2024-09-08 09:44:19

我在 Stackoverflow 上有一个类似的问题和类似的问题 - 我们的问题看起来几乎相同:) 检查一下 - 从 MySQL 获取 JSON 数据树

但我试图用一种稍微不同的方法来解决这个问题:我正在创建 JSON 对象。
所以我的新闻源表看起来像这样:

news_type   | datetime_added  | params
------------+-----------------+--------------------------------------------------------
new_photos  | 2010.12.01      | {user_id: "12", photo_id: "26", photo_url: "/images/photo.jpg"} 
new_comment | 2010.12.01      | {owner_id: "12", photo_id: "26", photo_url: "/images/photo.jpg", commenter_id: 25, comment_text: "Nice!"}

然后我在 php 中使用 json_decode 来创建数组。
然后根据 news_type 创建所需的 HTML。

I have a similar problem and similar question here on Stackoverflow - our questions look almost the same :) Check it - getting JSON data-tree from MySQL

But I'm trying to solve the problem in a little different approach: I'm creating JSON objects.
So my newsfeed table looks like this:

news_type   | datetime_added  | params
------------+-----------------+--------------------------------------------------------
new_photos  | 2010.12.01      | {user_id: "12", photo_id: "26", photo_url: "/images/photo.jpg"} 
new_comment | 2010.12.01      | {owner_id: "12", photo_id: "26", photo_url: "/images/photo.jpg", commenter_id: 25, comment_text: "Nice!"}

Then I use json_decode in php to create arrays.
Then depending on news_type I create needed HTML.

碍人泪离人颜 2024-09-08 09:44:19
  1. 是的,这是前进的最简单方法。这些消息的生存时间很短,因此如果您对存储的消息的 HTML 进行更改等,您将永远不需要及时更新它们。因此,您应该能够很好地使用它。

  2. 只需使用纯 HTML。它会很快,并且没有您稍后必须强制执行的关系,您永远不必能够更新这些或类似的内容。

编辑:我实际上误解了,我不知道您打算将这些 %s-things 作为您所引用的对象的一些特殊符号。我只会在该文本中放置纯 HTML 通知。

  1. Yes it's the bast way to move forward with this. Those are messages that live for a very short time so you'll never have to update them back in time if you make changes to the HTML of the message you store etc. So you should be in good shape using this.

  2. Just use the plain HTML. It will be fast and there are no relations that you will have to enforce later, you'll never have to be able to update those or anything like that.

Edit: I actually misunderstood, I didn't know you intended those %s-things to be some special notation for what objects you are referencing. I would just place plain HTML notifications in that text.

み青杉依旧 2024-09-08 09:44:19

当您谈论 Facebook 时,您必须想到发送者和接收者。

比如说您什么时候想查看发给 B 的所有消息/提要?那么你必须发起一个查询,对吧?我认为你的表看起来不错,但还添加了接收者 ID 列。也许你可以将其保存在单独的表中。

这样您就可以轻松找到用户 B来自用户 B从用户 A 到用户 B 的所有供稿,

希望这对您有帮助。

但如果您只想专注于提要,请忽略这一点。那么你只想要最新的。我认为在 Facebook 上我们可以看到任何人的个人资料以及他从 diff 获得的墙。用户。

谢谢。

When you are talking in regards to Facebook, you must think of sender and receiver.

Say when you want to see all messages/feeds to B? then you must fire a query right? I think your table seems fine, but also add column for receiver person's ID. May be you can keep that in separate table.

So that you can easily find all feeds for user B OR from user B OR from user A to user B

hope this might be helpful to you.

But ignore this if you only want to concentrate on feeds. then you want only the latest ones. What i thought is w.r.t. facebook where we can see anyone's profile with walls he got from diff. users.

thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文