确定用户是否查看过数据的最佳方式 [英] Best way to determine if a user has viewed data

查看:129
本文介绍了确定用户是否查看过数据的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定用户是否查看过一段数据的最佳方法是什么,如评论更新。我想到的两个解决方案是这些....

What is the best method to determine if a user has viewed a piece of data, ie like an update to a comment. The two solutions I have thought about are these....


  1. 使用一个单独的表,每个用户都有一行,在上次查看该项目时正在查看和插入的数据ID。

  1. Use a separate table that has a row for each user and the data id that is being viewed and inserting into when the item was last viewed.

使用相同的表格,并在项目为每个用户时为每个用户添加一行更改和删除该行当用户实际查看数据。

Use the same table and add a row for every user when the item is changed and delete that row when the user actually views the data.

这两种方法都可以解决问题,但在解决方案2中表的最大行数最差等于解决方案1,没有人查看任何内容,最多只有0行,所有内容都已被查看。我在解决方案2中知道,你无法确定何时被查看。

Both methods solve the problem but in solution 2 the maximum rows for the table would at worst equal that of solution 1, no one viewed anything, and at best has 0 rows, everything has been viewed. I know in solution 2 you have no way to determine when it was viewed.

想法?

编辑:我正在以评论更新为例。在实际应用中,不会期望新用户查看或读取旧数据。他们刚刚加入对他们来说意味着什么。

I was using an update to a comment as an example. In the actual application, new users wouldn't be expected to view or read old data. It would mean nothing to them for they just joined.

推荐答案

你需要知道他们查看了一段数据的时间或多少次?

do you need to know when or how many times they viewed a piece of data?

如果不是,我会保留一个带有FK的表格来更新数据,并将FK保存给用户。然后一个简单的检查,看看他们是否查看:

If not I'd keep a table with a FK to the data-updated and a FK to the user. then a simple check to see if they viewed:

select count(*) from DataAlerts where dataid = 1 and userid = 1

当数据更新时插入数据和用户的记录。

when data is updated insert records for the data and users.

当用户查看删除该用户。

when a user views delete that user.

这篇关于确定用户是否查看过数据的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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