search

Home  >  Q&A  >  body text

java - web应用中如何避免频繁点赞操作,比如点击又取消又点击如此循环?

巴扎黑巴扎黑2768 days ago1047

reply all(5)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:41:45

    Determine the uniqueness of likes based on IP, device number or some unique identifier, use a cache such as redis to update, and then write it to the database asynchronously and synchronously. If the liker is notified asynchronously, the click will be treated as an event and placed in a queue. It can be processed uniformly.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:41:45

    1. Lock likes. When sending a request for likes, lock the like button to prevent users from clicking it

    2. Directly feedback users' likes. Users are hard to perceive many details of this very simple operation. For a better user experience, you can directly display +1 the web style when giving a like, and then send a request to the backend. .
      The general like operation here is like this:

    +=============+        +----------------------------------+
    |   用户点赞   |  ----> |     直接回馈用户点赞成功          | 
    |             |  <---- |             样式+1               |
    +=============+        +----------------------------------+
                                          |                                
                                          |
                                 异步发送点赞请求 -----------------------> 后端接收,数据库完成点赞
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:41:45

    This is concurrency. It is impossible to remove all situations like this. Just introduce caching. Of course, you can do some global measures. If the number of clicks per second exceeds a warning, it will be similar to preventing some crawlers and a single IP. There is a click limit per unit time

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:41:45

    Remove the button after liking it

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:41:45

    Control the number of clicks, if there are too many clicks, you will be reminded

    reply
    0
  • Cancelreply