HotChocolate UsePaging 或 UseOffsetPaging 将查询速度减慢至 30 秒以上
我是 HotChocolate 和 graphql 的新手,但目前 HotChocolate 遇到的这个问题有点奇怪。
所以我在 dotnet 6.0 webapi 项目中使用以下包:
- HotChocolate.AspNetCore @ 12.5.0
- HotChocolate.AspNetCore.Authorization @ 12.5.0
- HotChocolate.Data @ 12.5.0
- HotChocolate.Types.Scalars @ 12.5.0
我有一个像下面这样查询
public IQueryable<EmploymentContract> GetEmploymentContracts([Service] ApplicationDbContext dbContext)
=> dbContext.EmploymentContracts
.Include(x => x.Person)
.Include(x => x.Organisation)
.Include(x => x.Department);
,然后像下面这样查询它的描述符
descriptor.Field(x => x.GetEmploymentContracts(_dbContext))
.UsePaging(options: new PagingOptions { DefaultPageSize = PAGE_SIZE, IncludeTotalCount = true })
.UseFiltering()
.UseSorting();
现在的问题是如果我运行如下查询,有时甚至需要 30 秒以上才能返回结果。我检查了 ef core
生成的 sql 查询
,并在 200ms
内以 mssql 运行。无论是什么减慢了请求速度,都是在 ef core 运行查询并从数据库获取结果之后发生的。
{
employmentContracts {
nodes {
personnelNumber
}
}
}
如您所见,上面的查询非常简单。
当我删除 UsePaging
时,它工作正常,我立即得到结果。
但如果没有,它要么会超时,要么会运行 22 秒左右...
编辑
问题已解决,问题不在于 GraphQL。 该模型在发生查询的地方存储了一些图像。模型已更改,问题不再发生。
I'm new to HotChocolate and graphql but this issue that I have at the moment with HotChocolate is a bit strange.
So I'm using the following packages in a dotnet 6.0 webapi project:
- HotChocolate.AspNetCore @ 12.5.0
- HotChocolate.AspNetCore.Authorization @ 12.5.0
- HotChocolate.Data @ 12.5.0
- HotChocolate.Types.Scalars @ 12.5.0
I have a query like beloew
public IQueryable<EmploymentContract> GetEmploymentContracts([Service] ApplicationDbContext dbContext)
=> dbContext.EmploymentContracts
.Include(x => x.Person)
.Include(x => x.Organisation)
.Include(x => x.Department);
and then a descriptor for it like
descriptor.Field(x => x.GetEmploymentContracts(_dbContext))
.UsePaging(options: new PagingOptions { DefaultPageSize = PAGE_SIZE, IncludeTotalCount = true })
.UseFiltering()
.UseSorting();
Now the issue is that if I run a query like below, it takes even sometimes more than 30 seconds to give back the results. I checked the ef core
generated sql query
and that runs in mssql in 200ms
. Whatever is slowing down the request, is happening after ef core runs the query and gets the result from the database.
{
employmentContracts {
nodes {
personnelNumber
}
}
}
As you see, the above query is really simple.
When I remove the UsePaging
it works fine and I get the results immediately.
But if not, it either will give a timeout
or will run for 22s or so...
Edit
The problem is solved and the issue was not with GraphQL.
The model had some images stored in places where the query was happening. The model is changed and the issue is not happening anymore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论