从数据库中为用户随机且不重复地获取唯一的照片

发布于 2025-01-05 07:24:30 字数 219 浏览 0 评论 0原文

我正在尝试创建一个网站,该网站随机检索用户的照片,并且不会重复特定用户的照片,直到用户看到所有照片并初始化该用户的记录。

我想为每个用户和照片(已保存 URL)表建立一个 user_photo 表,该表指定用户是否已经看过该照片,但如果有很多用户和很多照片,这将是一个巨大的记录。

我的问题是是否有更好的设计来更快、更高效地检索数据。

我看到了其他问题,但与特定用户处理无关。

I am trying to create a website that retrieves photos for users randomly and without repetition for specific user, till the user see all the photos and init the records for the user.

I thought to have for each user and photo(URL saved) table, a user_photo table, that specifies if the user already saw the photo, but in case of many users and many photos, this will be a huge record.

my question is if there is a better design to retrieve data faster and efficient.

I saw other questions but not related to specific user handling.

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

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

发布评论

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

评论(2

花开雨落又逢春i 2025-01-12 07:24:30
  1. 在照片表中创建一个 DateTime 类型的列。
  2. 现在,用当前日期时间值更新所有记录。
  3. 使用 Order by 子句升序选择记录
  4. 当您看到该记录时,用当前日期更新同一记录,然后使用步骤 3 下次获取该记录。

这肯定会对您有很大帮助...

编辑

以下是我的建议......

  1. 在从数据库中选择记录时,不要直接在 user_Photo 和照片表之间进行内/左连接。
  2. 创建一个临时表并插入所需的记录(我的意思是,在检索 User_ID => 1 的照片时,您需要从该表(user_Photo 表)中选择用户 ID => 1 - 照片并插入到本地临时表中好的?)
  3. 现在在照片和临时表之间进行左/内连接以按子句升序获取记录

希望这会对您有所帮助......

  1. Create a column in your photo table of DateTime type .
  2. Now, Update all the records with current date time value.
  3. Select a record with Order by clause Ascending
  4. When you have seen the record, update the same record with current date and now fetch the record next time using step 3.

This will definitely help you alot...

EDIT

Below is my suggestion....

  1. While going to select the records from database, don't go for Inner /Left Join directly between user_Photo and Photo Tables.
  2. Create a Temp table and insert the required records(I meant, while retrieving the photos for User_ID => 1, you need to select the User ID => 1 - photos from this table(user_Photo table) and insert into a Local temp table. Fine? )
  3. Do a Left/Inner Join now between Photo and Temp table to get the records with Order by Clause Ascending

Hope this will help you....

止于盛夏 2025-01-12 07:24:30

之一

  • “不重复”意味着保持状态,这意味着您已经提到过的表
  • 。以随机顺序选择所有照片一次,并缓存结果(网页、客户端等)

无论哪种方式,都没有优雅的解决方案......

"Without repetition" means keeping state, which means one of

  • a table as you've already mentioned.
  • select all photos once in a random order, and keep the results cached (web page, client etc)

Either way, there is no elegant solution...

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