Beispiel #1
0
 private void GetUserLikes(string currUserId)
 {
     // Get from cache
     userReviewLikesIds     = _userLikesCacheService.GetUserLikedReviewsIds(currUserId);
     userCommentLikesIds    = _userLikesCacheService.GetUserLikedCommentsIds(currUserId);
     userReviewDislikesIds  = _userLikesCacheService.GetUserDisikedReviewsIds(currUserId);
     userCommentDislikesIds = _userLikesCacheService.GetUserDisikedCommentsIds(currUserId);
     userPostLikesIds       = _userLikesCacheService.GetUserLikedPostsIds(currUserId);
     // If not check the Database
     if (userReviewLikesIds == null || userReviewLikesIds.Count() == 0)
     {
         userReviewLikesIds = _userLikesDataService.GetUserLikedReviewsIds(currUserId);
         _userLikesCacheService.SetUserLikedReviewsIds(currUserId, userReviewLikesIds, 20);
     }
     if (userCommentLikesIds == null || userCommentLikesIds.Count() == 0)
     {
         userCommentLikesIds = _userLikesDataService.GetUserLikedCommentsIds(currUserId);
         _userLikesCacheService.SetUserLikedCommentsIds(currUserId, userCommentLikesIds, 20);
     }
     if (userReviewDislikesIds == null || userReviewDislikesIds.Count() == 0)
     {
         userReviewDislikesIds = _userLikesDataService.GetUserDisikedReviewsIds(currUserId);
         _userLikesCacheService.SetUserDisikedReviewsIds(currUserId, userReviewDislikesIds, 20);
     }
     if (userCommentDislikesIds == null || userCommentDislikesIds.Count() == 0)
     {
         userCommentDislikesIds = _userLikesDataService.GetUserDisikedCommentsIds(currUserId);
         _userLikesCacheService.SetUserDisikedCommentsIds(currUserId, userCommentDislikesIds, 20);
     }
     if (userPostLikesIds == null || userPostLikesIds.Count() == 0)
     {
         userPostLikesIds = _userLikesDataService.GetUserLikedPostsIds(currUserId);
         _userLikesCacheService.SetUserLikedPostsIds(currUserId, userPostLikesIds, 20);
     }
 }
 private void GetUserPostLikes(string currUserId)
 {
     userPostLikesIds = _userLikesCacheService.GetUserLikedPostsIds(currUserId);
     if (userPostLikesIds == null || userPostLikesIds.Count() == 0)
     {
         userPostLikesIds = _userLikesDataService.GetUserLikedPostsIds(currUserId);
         _userLikesCacheService.SetUserLikedPostsIds(currUserId, userPostLikesIds, 20);
     }
 }
Beispiel #3
0
 private void GetUserLikes(string currUserId)
 {
     // Get from cache
     userReviewLikesIds     = _userLikesCacheService.GetUserLikedReviewsIds(currUserId);
     userCommentLikesIds    = _userLikesCacheService.GetUserLikedCommentsIds(currUserId);
     userReviewDislikesIds  = _userLikesCacheService.GetUserDisikedReviewsIds(currUserId);
     userCommentDislikesIds = _userLikesCacheService.GetUserDisikedCommentsIds(currUserId);
     userPostLikesIds       = _userLikesCacheService.GetUserLikedPostsIds(currUserId);
     userGroupFollowIds     = _userLikesCacheService.GetUserFollowingGroupsIds(currUserId);
     currentUserFollowings  = _userFollowCacheService.GetFollowingUserIds(currUserId);
     // If not check the Database
     if (userReviewLikesIds == null || userReviewLikesIds.Count() == 0)
     {
         userReviewLikesIds = _userLikesDataService.GetUserLikedReviewsIds(currUserId);
         _userLikesCacheService.SetUserLikedReviewsIds(currUserId, userReviewLikesIds, 20);
     }
     if (userCommentLikesIds == null || userCommentLikesIds.Count() == 0)
     {
         userCommentLikesIds = _userLikesDataService.GetUserLikedCommentsIds(currUserId);
         _userLikesCacheService.SetUserLikedCommentsIds(currUserId, userCommentLikesIds, 20);
     }
     if (userReviewDislikesIds == null || userReviewDislikesIds.Count() == 0)
     {
         userReviewDislikesIds = _userLikesDataService.GetUserDisikedReviewsIds(currUserId);
         _userLikesCacheService.SetUserDisikedReviewsIds(currUserId, userReviewDislikesIds, 20);
     }
     if (userCommentDislikesIds == null || userCommentDislikesIds.Count() == 0)
     {
         userCommentDislikesIds = _userLikesDataService.GetUserDisikedCommentsIds(currUserId);
         _userLikesCacheService.SetUserDisikedCommentsIds(currUserId, userCommentDislikesIds, 20);
     }
     if (userPostLikesIds == null || userPostLikesIds.Count() == 0)
     {
         userPostLikesIds = _userLikesDataService.GetUserLikedPostsIds(currUserId);
         _userLikesCacheService.SetUserLikedPostsIds(currUserId, userPostLikesIds, 20);
     }
     if (userGroupFollowIds == null || userGroupFollowIds.Count() == 0)
     {
         userGroupFollowIds = _userLikesDataService.GetUserFollowingGroups(currUserId, 30);
         _userLikesCacheService.SetUserFollowingGroupsIds(currUserId, userGroupFollowIds, 20);
     }
     if (currentUserFollowings == null || currentUserFollowings.Count == 0)
     {
         currentUserFollowings = _userLikesDataService.GetFollowingUserIds(currUserId);
         if (currentUserFollowings == null)
         {
             currentUserFollowings = new Dictionary <string, FollowState>();
         }
         else
         {
             _userFollowCacheService.SetFollowingUserIds(currUserId, currentUserFollowings, 10);
         }
     }
 }
Beispiel #4
0
        public PaginatedPostCardReturn GetUserFavourites(string userName, int pageIndex, int pageSize, string order, string currUserId)
        {
            bool isLoggedIn = !string.IsNullOrEmpty(currUserId);

            PaginatedPostCardReturn ret = new PaginatedPostCardReturn();

            if (isLoggedIn)
            {
                GetUserPostLikes(currUserId);
            }

            string userId = GetUserId(userName);

            int [] favPostLikesIds = _userLikesCacheService.GetUserLikedPostsIds(userId);
            if (favPostLikesIds == null || favPostLikesIds.Count() == 0)
            {
                favPostLikesIds = _userLikesDataService.GetUserLikedPostsIds(userId);
                _userLikesCacheService.SetUserLikedPostsIds(userId, favPostLikesIds, 20);
            }
            // Get Users post Count From Cache
            int?favouriteCount = favPostLikesIds.Count();

            // If null Get From Database and set Cache 60Min
            if (!favouriteCount.HasValue)
            {
                var favourites = _context.SetChild <UserPostLike>()
                                 .AsNoTracking().Where(p => p.UserInfoId == userId);

                favouriteCount = _context.SetChild <UserPostLike>()
                                 .AsNoTracking().Count(p => p.UserInfoId == userId);

                _userCacheService.SetUserFavouriteCount(userId, favouriteCount.Value, 60);
                if (favouriteCount == 0)
                {
                    return(ret);
                }
            }

            var entities = _context.Set <Post>()
                           .AsNoTracking()
                           .Where(p => favPostLikesIds.Skip((pageIndex - 1) * pageSize).Take(pageSize).Contains(p.Id) && p.IsPublished)
                           .OrderByDescending(p => p.DateUtcPublished)
                           .Skip((pageIndex - 1) * pageSize)
                           .Take(pageSize)
                           .Select(p => new PostCardModel()
            {
                DateUtcPublished = p.DateUtcPublished,
                AuthorInfo       = new UserCardModel()
                {
                    AppUserId    = p.UserInfoId,
                    Name         = p.UserInfo.Name,
                    Username     = p.UserInfo.UName,
                    Surname      = p.UserInfo.Surname,
                    ProfileImage = p.UserInfo.ProfilePicture.SmallPath
                },
                Content   = p.Content,
                Title     = p.Title,
                PostParts = p.PostParts.Select(f => new PostPartDisplay()
                {
                    Description = f.Description,
                    Image       = new BaseImageReturn()
                    {
                        Dimension = f.Image.ImageDimension,
                        Extension = f.Image.FileExtension,
                        LazyUrl   = f.Image.BlurLazyPath,
                        ThumbUrl  = f.Image.ThumbPath,
                        Url       = f.Image.ResizedPath,
                        SmallUrl  = f.Image.SmallPath
                    },
                    Title = f.Title,
                    Id    = f.Id
                }).ToList(),
                Id = p.Id,
            }).ToList();

            foreach (var post in entities)
            {
                post.IsCurrentUserLiked = userPostLikesIds.Contains(post.Id);
                post.FavouriteCount     = _postCacheService.GetPostLikesCount(post.Id)
                                          ?? _postDataService.GetPostLikeCount(post.Id, cacheTreshold: 20);
                post.ReviewCount = _postDataService.GetPostReviewsCount(post.Id);
                post.Rating      = GetPostRating(post.Id, 30);
            }
            ret.Entities = entities.ToPaginatedList(pageIndex, pageSize, favouriteCount.Value);
            return(ret);
        }