跟踪上次查看的访问者项目

I have a very AJAX-ish listing webpage created using Codeigniter where I want registered users to be able to differentiate which listings they have viewed previously.

Current Attempt: On clicking the listing, the listing id is sent vis $.post() to serverside PHP, which inserts(using INSERT... ON DUPLICATE KEY UPDATE) the listing_id, user_id, view_timestamp into a table with viewed_id on autoincrement. Everytime the visitor does a new search, all the listing_id with his user_id is retrieved from the MySQL table via .getJSON(), and through a loop, the CSS of these previously viewed listings are changed.

My conern is whether this method involves too much work on the server.

  1. Will each user have a single row be better, with the listing_id viewed be serialized?
  2. Should I use cookies(automatically saved into database by Codeigniter?) instead?
  3. Insert new listings viewed via AJAX when user views it. But only retrieves the list of viewed listings' id once if cookie containing all the viewed listing ids does not exist, else after sending newly viewed listings to the server to be inserted, the listing id is also inserted into the cookie. This way after doing new searches, there is no need to continuously query the database for the entire list of viewed listing ids.

Note: For an estimate of number of AJAX requests for previously viewed listings' listing_id, average user will do a new search every 20 secs.

Spontaneously for this kind of functionality I wouldn't involve the database and look at client-side solutions instead, like storing Json with the data using localStorage or alternatively cookies if you want wider browser support (or need to store it from your php-code and can't do it from the javascript). If you have to store this information in your database, I would still look at solutions to cache the information on the client as much as possible, like how you described it in point 3.