Esempio n. 1
0
 public Page GetUserLine(long userId, int pageIndex, int pageSize, long pageHeaderId = long.MaxValue)
 {
     var following = GetFollowing(userId);
     using (new TransactionScope())
     {
         using (var session = _store.OpenSession())
         {
             var skipCounter = 0;
             if (pageHeaderId != -1)
             {
                 skipCounter = session.Query<TwitterStatus>()
                     .Count(status => status.InternalId > pageHeaderId);
             }
             var t = session.Query<TwitterStatus>().OrderByDescending(x => x.CreatedAt)
                 .Where(status => status.UserIdStr.In(following))
                 .Skip(skipCounter)
                 .Take(pageSize).ToList();
             var page = new Page(t);
             return page;
         }
     }
 }
Esempio n. 2
0
        public Page GetPageBefore(long userId, int pageIndex, int pageSize, long pageHeaderId = 0)
        {
            var following = GetFollowing(userId);
            using (new TransactionScope())
            {//problem in logic
                using (var session = _store.OpenSession())
                {
                    var skipCounter = 0;
                    if (pageHeaderId != -1)
                    {
                        skipCounter = session.Query<TwitterStatus>()
                            .Count(status => status.InternalId > pageHeaderId);
                        skipCounter -= (pageIndex + 1) * pageSize;
                    }
                    if (skipCounter < -pageSize)
                    {
                        return  new Page(new List<TwitterStatus>());
                    }
                    if (skipCounter < 0)
                    {
                        var f = session.Query<TwitterStatus>().OrderByDescending(x => x.CreatedAt)
                        .Where(status => status.UserIdStr.In(following))
                        .Take(pageSize+skipCounter)
                        .ToList();
                        return new Page(f);

                    }
                    var r = session.Query<TwitterStatus>()
                        .Where(status => status.InternalId > pageHeaderId && status.UserIdStr.In(following)).OrderByDescending(x => x.CreatedAt, new DateTimeComparer()).Skip(pageIndex * pageSize)
                        .Take(pageSize).ToList();
                    var t = session.Query<TwitterStatus>().OrderByDescending(x => x.CreatedAt)
                        .Where(status => status.UserIdStr.In(following))
                        .Skip(skipCounter)
                        .Take(pageSize)
                        .ToList();
                    var page = new Page(t);
                    return page;
                }
            }
        }