DataLoader does not de-dupe keys when not configured to cache.
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js
- 领域
- backend
调研方向
从使用 cache: false 构造 DataLoader 开始,跟踪 load(1) 经过批量分发和结果映射的过程。添加一个回归测试,证明重复的键会以唯一形式传递给批处理函数,同时每个请求仍能收到自己的结果;当这一行为在没有内存缓存的情况下正常工作时,该 issue 即完成。
由索引模型根据 Issue 内容生成。
描述
Expected Behavior
If I pass in multiple identical keys, then the batch function should only be called with the unique set of keys, even if not caching (they are still identical requests.)
Current Behavior
The data loader does not de-duplicate the keys and they are passed along in full to the batch function,.
Possible Solution
The data loader should still de-duplicate the keys. My understanding of "cache" is about whether the results are kept in memory after the batch function is called, not whether or not they are batched up. So I would expect that the data loader would still keep map the unique set of results back to each request which asked for those keys.
Steps to Reproduce
Create a DataLoader with {cache: false} as the options.
Call load(1) twice.
Let the batch function get called.
Note that the value 1 will be present twice in the keys.
Context
We have designed our batch functions to expect each key only once, since that is what the data loader supplies in "normal" cases (normal = cache: true). However, we have recently written a thin wrapper around a data loader, which actually delegates the caching part to Redis so we can get caching across processes / machines. Note that Redis is the backing store for the cache, it is NOT the place the real batch function goes to get data.
As such we just wrap a DataLoader with a simple class that takes the options and the actual batch function, and stores those, but create a data loader inside the object with whatever the supplied data loader options were, but with cache: false. This data loader is given a batch function which is just a closure function which will then go and look things up in Redis and only call the underlying real batch function with the set of keys which are not in the cache.
We can turn this on and off as for our local developers there was no need to force them to spin up a Redis instance, so our code can configurable instantiate a native DataLoader or a CachingDataLoader. We noticed we got some very odd behaviour only when using the caching data loader and after investigation we discovered that this was because our caching data loader batch function was receiving duplicate keys. We were merrily passing these on to our underlying real batch function when there was a cache miss as we assumed they were unique. Our batch functions were all written when we weren't using this and hence they had never been tested with duplicate keys. Granted perhaps we should have tested them but we didn't because at the time it seemed it could never happen.
We have written some code in our caching data loader batch function which de-dupes the list, but semantically it felt wrong that the data loader would not de-dupe the list when it was not caching the results in memory. It felt like the logic of taking in multiple requests across a set of (sometimes repeating) keys and then farming out the responses from the batch function to those requests, should be orthogonal to whether or not those responses were held in memory afterwards or not. Hence the "bug." Perhaps this is a feature request, not entirely sure but it felt disconnected enough from expected behaviour that I've opted to file it as a bug for now. :)
- 主要语言
- JavaScript
- 星标
- 13.4k
- 派生
- 522
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql/dataloader 的其他 Issue
-
[BUG] `maxBatchSize: NaN` is accepted and silently disables batching可能已有人在做 @RaphaelFakhri 于 3 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
graphql/dataloader#405 ·
-
Failed batch evicts a replacement cache entry after clear/prime可能已有人在做 @Claire-ovo 于 12 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 57/100
graphql/dataloader#403 ·
-
enhancement
难度 5/5 一周以上 新手友好度 38/100
graphql/dataloader#393 ·
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
graphql/dataloader#382 ·
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
graphql/dataloader#379 · 2 条评论 · 5 个 reaction ·
查看 graphql/dataloader 的全部 Issue
相似的 Issue
-
[docs] RELEASE.md: wrong branch name, no check that the prepare PR merged with the right subject, manual publish step可能已有人在做 @albertteoh 今天认领。 未关闭documentation
难度 2/5 1-3 小时 新手友好度 85/100
jaegertracing/jaeger-ui#4739 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 74/100
keepassxreboot/keepassxc-browser#3159 · 1 条评论 ·
-
Add: ESP 2 RS未关闭approved check:passed feeds:add
难度 1/5 1 小时以内 新手友好度 67/100
-
v6: OTP input keeps the rest of a selection when you type over it可能已有人在做 @thejesh23 今天认领。 未关闭bug confirmed has-pr js v6
难度 2/5 1-3 小时 新手友好度 82/100
twbs/bootstrap#43323 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复