处理类似csdn下载的性能问题【欢迎大家讨论】

WBOY
Release: 2016-06-23 14:23:57
Original
1100 people have browsed it

在csdn的下载频道中,如果用户下载过该附件,当下次再下载时就不需要在扣除积分了。
我目前有个类似的功能,我的实现方案是在我的附件表中增加一个字段:download_uids用来存储所有下载过该附件的用户id。然后当用户下载的时候首先用in_array()函数看用户uid是否在该附件记录的中download_uids存在,如果存在不执行扣除金币操作,反之执行扣除金币操作再执行array_push。

关键点:in_array()对大数组(最多30k用户)的操作是否存在性能问题。
大数组array_push()对大数组(最多30k用户)是否有性能问题


回复讨论(解决方案)

新建一表,2字段
uid 保存用户id
did 保存资源id

查询用户是否下载过某资源
select * from tbl_name where uid=$uid and did=$did

查询用户下载过那些资源
select * from tbl_name where uid=$uid

查询都有哪些用户下载了某资源
select * from tbl_name where did=$did

新建一表,2字段
uid 保存用户id
did 保存资源id

查询用户是否下载过某资源
select * from tbl_name where uid=$uid and did=$did

查询用户下载过那些资源
select * from tbl_name where uid=$uid

查询都有哪些用户下载了某资源
select * from tbl_name where did=$did
谢谢斑竹,受教了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!