Youtube如何记住点赞? [英] How does Youtube remember Likes?

查看:649
本文介绍了Youtube如何记住点赞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我想知道YouTube等网站如何记住用户喜欢"视频并阻止他们再次喜欢它.同样,像Reddit这样的网站如何记住已投票和已拒绝的内容,并防止用户对其已被投票的内容进行投票.

So I'm wondering how sites like YouTube remember when a user has "Liked" a video and prevents them from liking it again. Similarly, how a site like Reddit remembers upvotes and downvotes and prevents a user from upvoting a piece of content they already upvoted.

它像数据库表一样简单,在表中存储了内容的ID以及用户的ID及其响应.我觉得那将成为一张巨大的桌子.有什么棘手的事情吗?

Is it as simple as a database table where the ID of the content is stored along with the ID of the user and their response? I feel like that would become a massively huge table. Is there something trickier going on?

推荐答案

我的页面上有一个喜欢/不喜欢的系统.

I have a like/dislike system on my page.

数据库表:

1.)其中包含您的帖子,每个帖子具有唯一的ID,以及创建该帖子的用户的user_id(以及其他信息,例如内容,标签等).

1.) One that contains your posts with a unique ID for each post and a user_id of who created it (along with other info like content, tags, etc).

2.)至少用likes调用的表包含以下字段,ID,post_id(对应于帖子表中被喜欢或不喜欢的帖子),user_id(对应于用户表中喜欢该操作的用户/不喜欢),状态(0或1、0喜欢该职位,1不喜欢该职位).

2.) table called likes with AT LEAST the following fields, ID, post_id (corresponds to the post in the post table that was liked or disliked), user_id (corresponds to the user in the users table that did the liking/disliking), status (0 or 1, 0 being liked the post, 1 being disliked the post).

当用户喜欢帖子时,将其用户名和post_id插入行到likes表中,将状态设置为0(或因为默认为0而留空).当用户不喜欢该帖子时,请执行相同操作,但将状态设置为1.

When a user likes a post, insert the row into the likes table with their user_id and the post_id, set the status as 0 (or just leave empty because 0 is the default). When a user dislikes a post, do the same but set the status as 1.

这样,您可以在帖子页面上获得喜欢或不喜欢该帖子的所有用户的人数.在用户的个人资料页面上,您可以获取用户喜欢或不喜欢的所有帖子.您还可以对喜欢或不喜欢最多的帖子进行排名.甚至可以根据发布了喜欢或不喜欢的内容的用户对特定用户进行排名.

That way, on a post page you can get the count of all the users that liked or disliked a post. On a users's profile page, you can get all of the posts a user either likes or dislikes. You can also rank posts by which has the most likes or dislikes. Or even rank specific users by who has posted content with the most likes or dislikes.

如果用户已经在数据库中有记录,则不允许用户喜欢/不喜欢该帖子. (基本上只需检查Likes表中的记录数,其中post_id等于当前帖子,而user_id等于已登录的用户)

Do not allow a users to like/dislike a post if they already have a record in the database. (Basically just check the count of records in the likes table where the post_id is equal to the current post and user_id is equal to the logged in user)

交叉引用帖子表以获取帖子作者的user_id.如果帖子作者user_id与登录用户相同,或者该用户当前尚未登录,则不允许他们投票.

Cross reference the post table to get the post's author's user_id. If the post author user_id is the same as the logged in user, or the user is NOT currently logged in, do not allow them to vote.

执行所有这些操作的查询很简单(只需SELECT *或SELECT user_id),但这是基本思想.

The queries for doing all of those are simple (simply SELECT * or SELECT user_id) but that is the basic idea.

这篇关于Youtube如何记住点赞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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