Handles performance-related issues like CSDN downloads "Welcome to the discussion."

Source: Internet
Author: User
Handling performance issues like CSDN downloads "Welcome to the discussion."
In Csdn's download channel, if the user downloads the attachment, the next time you download it, you don't need to deduct points.
I currently have a similar feature, and my implementation is to add a field to my attachment table: Download_uids is used to store all the user IDs that have been downloaded for that attachment. Then when the user downloads the first time to use the In_array () function to see if the user UID in the attachment record download_uids exist, if there is not to perform the deduction of gold operation, and vice versa to perform the deduction of gold Array_push.

Key point: In_array () has a performance problem with operations on large arrays (up to 30k users).
Large Array Array_push () has performance issues with large arrays (up to 30k users)

Share to:


------Solution--------------------
Create a new table, 2 fields
UID Save User ID
Did save resource ID

Query whether a user has downloaded a resource
SELECT * from Tbl_name where uid= $uid and did= $did

Query users to download those resources
SELECT * from Tbl_name where uid= $uid

Query which users have downloaded a resource
SELECT * from Tbl_name where did= $did

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.