首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

关于‘新近访客’的一些想法

2012-11-13 
关于‘最近访客’的一些想法问题描述最近访客功能记录个人空间被哪些用户访问过入口问题进入用户个人空间的

关于‘最近访客’的一些想法
问题描述
最近访客功能记录个人空间被哪些用户访问过

入口问题
进入用户个人空间的入口颇多

http://xuliangyong.iteye.comhttp://xuliangyong.iteye.com/blog/342762http://xuliangyong.iteye.com/category/46687http://xuliangyong.iteye.com/blog/pdf

是对所有入口都处理还是有选择的处理 根据自身环境定

写数据库频率
入口确定后 接下来是将访客的id写入数据库
每次访问都写数据库是不现实的,可采用 cookie或session控制写如数据库的频率
逻辑为

if( !existMyCookie ){    writeDB();    writeMyCookie(expireDate);}


写数据库策略
访客可能在以前访问过我的空间 所以需要判断数据库中访客存在否
有两种方法判断
1 进攻式写入---假设访客以前访问过我的空间,直接update,返回1表示假设成立; 返回0则进行insert
2 防御式写入---先查询存在否,后进行update或insert

第一种方式有时访问1次数据库 有时访问两次
第二种方式需两次


insert into `sns_user_visitor`(host_id, visitor_id, visit_time) select 34, 35, '2009-1-1' from dual where not EXISTS( select id from  `sns_user_visitor` where host_id = 34 and visitor_id=35);


热点排行