上载到Azure时,EF核心性能会降低

问题描述

我目前正在使用EFCore 3.0。我有一个查询,该查询数据库获取记录,这些记录在本地主机上运行在一秒钟之内,但在Azure Web Service上运行则超过10秒。

我编写的代码是根据用户的连接从数据库中检索所有用户帖子,类似社交留言之类的想法。首先将这些标头检索为IQueryable,然后根据页码页面大小将其处理为IEnumerable。

PostHeaders中有数百条记录。这是在EFCore中处理数据查询的正确方法吗?

这是我的EF代码,用于从数据库检索帖子:

public async Task<PagedList<PostHeader>> GetPosts(int socialProfileId,SocialPostHeaderParams socialPostHeaderParams)
    {
        List<int> userConnectionIds = await _context.socialConnections
            .Where(sc => sc.FirstSUPId == socialProfileId && sc.Status == "Connected")
            .Select(sc => sc.SecondSUPId)
            .ToListAsync();

        userConnectionIds.Add(socialProfileId);


        IQueryable<PostHeader> postHeadersToReturn = _context.PostHeaders
            .Include(u => u.socialUserProfile)
                .ThenInclude(sup => sup.socialAlbums)
                    .ThenInclude(sa => sa.socialPhotos)
            .Include(ps => ps.PostStatus)
                .ThenInclude(psp => psp.PostPictures)
            .Include(pc => pc.PostComments)
            .Include(ph => ph.PostHearts)
            .Where(ph => (userConnectionIds.Contains(ph.CreatedBySUPId) && ph.socialGroupId == 0 && ph.socialPageId == 0 && ph.Enabled))
            .OrderByDescending(ph => ph.Created)
            .AsQueryable();

        return await PagedList<PostHeader>.CreateAsync(postHeadersToReturn,socialPostHeaderParams.PageNumber,socialPostHeaderParams.PageSize);
    }


public static async Task<PagedList<T>> CreateAsync(IQueryable<T> source,int pageNumber,int pageSize)
    {
        var count = await source.CountAsync();
        var items = await source.Skip((pageNumber -1) * pageSize).Take(pageSize).ToListAsync();

        return new PagedList<T>(items,count,pageNumber,pageSize);
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)