ds2321 2016-10-28 02:58
浏览 14

为系统[重复]等帖子设计数据库架构的最佳方法

I was wondering if i should create a separate table for likes counter and storing post id and user id for likes.

Ex table: ID, post_id, User_id

or should if put it in users table to keep database clean and small like this:

Ex already existing users_meta table(Wordpress)

User_id, post_likes(meta_value), post_ids(array(2,3,4,5,6))

So whenever user likes a post, just push the post id to specific user's table.


The idea of putting id's in user meta table is. It will keep the database system small and easy for finding if user has liked any post.

Please correct me if i'm wrong!

</div>
  • 写回答

1条回答 默认 最新

  • drbvm26000 2016-10-28 03:05
    关注

    I'd say the best argument for storing the post id's in user meta is that you don't have to rewrite a bunch of functions from scratch to interact with a brand new table in the database. You can use the prebuilt WordPress functions like update_user_meta(), etc to do the reading / writing.

    I've seen this exact use done by storing all the posts a user 'liked' as a serialized array in a user meta field via the maybe_serialize function:

    https://codex.wordpress.org/Function_Reference/maybe_serialize

    You create an array of post ids, run it through maybe_serialize(), and then save it as a value to the user's meta table. Pretty clean and simple.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度