示例#1
0
        public PaginatedInterestCard GetUserInterests(string currUserId, PaginatedRequest req)
        {
            PaginatedInterestCard ret = new PaginatedInterestCard();

            userGroupFollowIds = _userLikesCacheService.GetUserFollowingGroupsIds(currUserId);
            if (userGroupFollowIds == null || userGroupFollowIds.Count() == 0)
            {
                userGroupFollowIds = _userLikesDataService.GetUserFollowingGroups(currUserId, 30);
                _userLikesCacheService.SetUserFollowingGroupsIds(currUserId, userGroupFollowIds, 20);
            }
            int total = userGroupFollowIds.Count();

            if (total < 1)
            {
                return(ret);
            }
            int[] paginatedIds = userGroupFollowIds.Skip((req.PageIndex - 1) * req.PageSize).Take(req.PageSize).ToArray();
            ret.Entities = _context.Set <Group>().AsNoTracking()
                           .Select(f => new { Entity = f, f.ProfileImage })
                           .Where(p => paginatedIds.Contains(p.Entity.Id))
                           .Select(p => new InterestCard()
            {
                AlphaColor             = p.Entity.ColorAlpha,
                UrlKey                 = p.Entity.UrlKey,
                Id                     = p.Entity.Id,
                Name                   = p.Entity.Name,
                IsCurrentUserFollowing = true,
                ProfileImage           = p.Entity.ProfileImage.SmallPath
            }).ToPaginatedList(req.PageIndex, req.PageSize, total);

            return(ret);
        }
示例#2
0
        public PaginatedInterestCard GetExploreInterests(PaginatedLangRequest req, string currUserId)
        {
            userFollowedInterest = _userLikesCacheService.GetUserFollowingGroupsIds(currUserId);
            if (userFollowedInterest == null || userFollowedInterest.Count() == 0)
            {
                userFollowedInterest = _userLikesDataService.GetUserFollowingGroups(currUserId, 5);
                _userLikesCacheService.SetUserFollowingGroupsIds(currUserId, userFollowedInterest, 20);
            }
            PaginatedInterestCard ret = new PaginatedInterestCard();

            int[] langCodeTrendingInterestIds = _exploreCacheService.GetExploreInterestIds(req.LangCode, req.PageIndex);
            int?  totalGroupCount             = _commonCacheService.GetTotalGroupCount();

            if (!totalGroupCount.HasValue)
            {
                totalGroupCount = _context.Set <Group>().Count();
                _commonCacheService.SetTotalGroupCount(totalGroupCount.Value, 10);
            }
            if (langCodeTrendingInterestIds == null || langCodeTrendingInterestIds.Count() == 0)
            {
                // Order by follower count
                langCodeTrendingInterestIds = _context.Set <Group>()
                                              .AsNoTracking()
                                              .SelectMany(a => a.UsersFollowing)
                                              .GroupBy(t => t.GroupId, (k, g) => new
                {
                    GroupId = k,
                    gs      = g,
                    Count   = g.Count(q => q.GroupFollowState == GroupFollowState.Followed)
                })
                                              .OrderByDescending(g => g.Count)
                                              .Select(f => f.GroupId)
                                              .Distinct()
                                              .Skip((req.PageIndex - 1) * req.PageSize)
                                              .Take(req.PageSize)
                                              .ToArray();
                if (langCodeTrendingInterestIds != null)
                {
                    if (langCodeTrendingInterestIds.Length > req.PageSize)
                    {
                        _exploreCacheService.SetExploreInterestIds(req.LangCode, req.PageIndex, langCodeTrendingInterestIds, 60 * 24);
                    }
                }
            }
            ret.Entities = _context.Set <Group>().AsNoTracking()
                           .Select(p => new { Entity = p, Image = p.ProfileImage, p.CoverImage })
                           .Where(p => langCodeTrendingInterestIds.Contains(p.Entity.Id))
                           .Select(p => new InterestCard()
            {
                AlphaColor             = p.Entity.ColorAlpha,
                Id                     = p.Entity.Id,
                Name                   = p.Entity.Name,
                UrlKey                 = p.Entity.UrlKey,
                IsCurrentUserFollowing = userFollowedInterest.Contains(p.Entity.Id),
                ProfileImage           = p.Image.SmallPath,
                CoverImage             = p.CoverImage.ThumbPath
            })
                           .ToPaginatedList(req.PageIndex, req.PageSize, totalGroupCount.Value);
            return(ret);
        }
示例#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);
         }
     }
 }