PHP forums - how to cope with unread discussions / topics / posts

后端 未结 7 1031
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 17:10

I know this question has been asked here a couple of times, but none of the answers had pleased me. This is because almost all of them involve a huge read / write process re

7条回答
  •  不思量自难忘°
    2020-12-07 17:31

    Non exactly a PHP-answer, but here's how we do it in our asp.net-based forum (I'm affiliated with this product, disclosing that due to the rules)

    1. We use cookies, not the database.
      • Disadvantage of cookies - not "cross-device" (visiting from another computer shows everything as unread)
      • Advantage - no huge DB reads/writes. And tracking works for "guest" users also! This is awesome.
    2. We store a cookie with { topicID, lastReadMessageID } pairs for every topic the user visits.
    3. If the data for a particular topic is not found in the cookie we assume the topic is either:
      • fully unread (if the topic's last message is greater than MAX lastReadMessageID from (2)
      • fully read (if otherwise)

    This has some minor flaws, but it does the job.

    PS. Also, some might say that using cookies leaves garbage on the user's computer (I personally hate this), but we found out that an average user tracks about 20 topics tops, so it takes about 10 bytes per topic so it takes less than 200 bytes on the user's harddrive.

提交回复
热议问题