今天将Blog的数据访问层作了修改,调用存储过程来实现首页、分类页、评论页等数据量稍大的页面。
原来的方式是将上述页面作服务器端的Cache,数据小的时候无所谓,但随着量的增大,在内存方面的开销就显得稍大了。
刚好有点时间,重写了数据层,
/// <summary>
        /// 获取首页数据源
        /// </summary>
        /// <param name="pagesize">分页数</param>
        /// <param name="pageindex">当前页码</param>
        /// <param name="pagecount">总页数</param>
        /// <param name="recordcount">总记录数</param>
        /// <returns>DataTable</returns>
        public DataTable GetIndexDataSource(int pagesize,int pageindex,out int pagecount,out int recordcount)
        {
            SqlParameter[] para = new SqlParameter[8];
            para[0] = new SqlParameter("@Tables", "documents");
            para[1] = new SqlParameter("@PK", "documentid");
            para[2] = new SqlParameter("@Sort", " istop desc, publishdate desc");
            para[3] = new SqlParameter("@PageNumber", pageindex);
            para[4] = new SqlParameter("@PageSize", pagesize);
            para[5] = new SqlParameter("@Fields", " *");
            para[6] = new SqlParameter("@Filter", " ispublish = 1");
            para[7] = new SqlParameter("@Group", DBNull.Value);
            return SqlHelper.ExecuteDataTable("Paging_SubQuery", CommandType.StoredProcedure, para, out pagecount, out recordcount);
        }

但Paging_SubQuery存储过程的代码还需优化,因为在取得记录总数时是用的Select Count(0)来获取的,这个效率不是很高。
这样一改进可以省去约100个服务器缓存

8 Responses

  1. hubro 一月 11 2007 , 16:12
    静态成岁
    #1
  2. hubro 一月 11 2007 , 16:12
    万岁...
    #2
  3. 下一秒 一月 11 2007 , 16:22
    难怪速度又感觉快了很多,我那个慢死了。NND[em10]
    #3
  4. 幻想曲 一月 11 2007 , 16:32
    幻想曲
    生成静态搞么丝喔~~
    伪静态就行鸟
    闪~~
    #4
  5. 磊磊 一月 14 2007 , 03:12
    CSDN好像就是幻想曲说的伪静态,上次被我发现了!

    嘻嘻~~~[em11]
    #5
  6. 下一秒 一月 14 2007 , 18:09
    武汉下雪了
    #6
  7. 幻想曲 一月 14 2007 , 18:54
    幻想曲
    早上小龚在QQ里说起过
    据说雪花还不小啊~~
    上海是没指望了
    #7
  8. 幻想曲 一月 15 2007 , 09:53
    幻想曲
    这个访问量有点怪啊
    怎么就2W多点击了[em13]
    #8

Write a comment:



(将显示你的Gravatar图标)  



[b][/b] - [i][/i] - [u][/u]- [quote][/quote]

:-/ ^_^ :d :o :kiss: :) :p :se: [yeah] :( :love: :han: :up: :cry: :zzz: o_o

评论提交有问题?