简体   繁体   English

在活动供稿中将类似活动分组

[英]Group similar activities in a activity feed

After searching Google and Stackoverflow for similar questions, i still haven't found any solution. 在Google和Stackoverflow搜索类似问题之后,我仍然没有找到任何解决方案。

One of the main parts of my site are activity feeds. 我网站的主要部分之一是活动供稿。 It show all the actions different users did just like Facebook. 它显示了不同用户像Facebook一样执行的所有操作。 I store all the activities in a MySQL table, and render the view with PHP. 我将所有活动存储在MySQL表中,并使用PHP渲染视图。

I want to group similar activities just like Facebook does: 我想像Facebook一样对类似的活动进行分组:

*Current situation:*
 - User A uploaded a picture
 - User A uploaded a picture

*Desired situation:*
 - User A uploaded 2 pictures

My activity table looks like this: 我的活动表如下所示:

[Activities]
  - i_id
  - a_source
  - a_type
  - a_parent
  - a_parent_id
  - a_data (json string with meta data, photo filenames for example)

I have found these questions on stackoverflow, but none of them provide a solution: 我在stackoverflow上发现了以下问题,但没有一个提供解决方案:

  1. https://stackoverflow.com/questions/5844655/how-to-group-similar-items-in-activity-feed-similar-to-facebook https://stackoverflow.com/questions/5844655/how-to-group-similar-items-in-activity-feed-similar-to-facebook
  2. User activity feed (ala facebook). 用户活动供稿(ala facebook)。 How to group similar activities? 如何分组类似的活动?
  3. How to group similar items in an activity feed 如何将活动供稿中的相似项目分组

:edit: :编辑:

I'm looking for an approach and want your thoughts on how to solve this. 我正在寻找一种方法,希望您对如何解决这个问题有想法。

Would it be best to run a cron job and group all the same items in the db? 最好执行cron作业并将db中所有相同的项目分组吗? Or would it be better to do this on render time with php? 还是在用php渲染时间上这样做更好?

I prefer a (realtime) php solution but then again i don't know where to start. 我更喜欢(实时)php解决方案,但是我又不知道从哪里开始。

I just need a starting point for future reading. 我只需要将来阅读的起点。

I'm looking for an approach and want your thoughts on how to solve this. 我正在寻找一种方法,希望您对如何解决这个问题有想法。

Short answer? 简短的答案? GROUP BY

Answer based purely on assumptions? 纯粹基于假设回答? Below: 下面:

Coding blindly, since you haven't provided anything else aside from the situations and table columns: 盲目编码,因为除了situations和表列之外,您没有提供其他任何内容:

Assumed data for columns that appear to make sense at the moment (again, without seeing any data): 目前似乎有意义的列的假设数据(再次,看不到任何数据):

i_id    a_type
123     photo upload
123     photo upload
123     comment

With: i_id -being a user id a_type -being a type of activity 使用:i_id-是用户ID a_type-是活动类型

Just do: 做就是了:

SELECT a.i_id, a.a_type, COUNT(1) AS activity_count
FROM activities AS a
WHERE a.i_id = 123 -- or convert this to a parameter through PHP->PDO
GROUP BY a.i_id, a_type

The SQL above should give you: 上面的SQL应该给您:

i_id    a_type          activity_count
123     photo upload    2

Would it be best to run a cron job and group all the same items in the db? 最好执行cron作业并将db中所有相同的项目分组吗? Or would it be better to do this on render time with php? 还是在用php渲染时间上这样做更好?

Do you need aggregated data? 您是否需要汇总数据? Does the activities table have millions and millions and millions and.... of data or does it expect to have that much data? activities表中是否包含数百万,数以百万计的数据,还是期望有那么多数据? Do you need reports on summaries of activities per user? 您是否需要有关每个用户的活动摘要的报告? Will you mostly utilize the table for reports? 您会主要利用表格进行报告吗? Will you be partitioning this table and archive data out hence needing only aggregated data for future checks or reports? 您是否会对该表进行分区并存档数据,因此仅需要汇总数据即可用于将来的检查或报告?

I prefer a (realtime) php solution but then again i don't know where to start. 我更喜欢(实时)php解决方案,但是我又不知道从哪里开始。

You can search in google for real PHP solutions. 您可以在Google中搜索真正的PHP解决方案。 This stackoverflow isn't likely to be the place where you'll get one. 这种stackoverflow不太可能成为您的理想选择。 Links, maybe. 链接,也许。

I just need a starting point for future reading. 我只需要将来阅读的起点。

LINK: On GROUP BY 链接:在GROUP BY上

LINK: On PDO 链接:在PDO上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM