[BUG] Cached calls to `load()` still result in new Promise creation

オープン
#377 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, node.js

調査の方向性

src/index.js の 92 行目付近から始め、キャッシュパスを promise の作成に関するドキュメントの記述と比較してください。コミット 06c403bd72abef401dd7619c8ae992f03ed6b7d3 を確認し、繰り返しのロードでバッチ処理の動作を変更せずにキャッシュされた promise を再利用すべきか判断してください。完了の条件は、その動作が焦点を絞ったテストでカバーされていることです。

索引モデルが issue の本文から書いたものです。

説明

bug

Expected Behavior

The docs state creating a new Promise and new key in the batchLoadFn for every load of the same key. When loading large datasets that can contain large amounts of duplicates this means we could call load(1) 100k times and we should get 1 total promise.

Current Behavior

The source code reveals that whether or not we use the cache, we still end up creating a new promise. https://github.com/graphql/dataloader/blob/main/src/index.js#L92 .

Possible Solution

Why not just return the cachedPromise?

Context

It looks like the change originates from https://github.com/graphql/dataloader/commit/06c403bd72abef401dd7619c8ae992f03ed6b7d3 . It's been many years, but the reasoning behind that change feels misguided maybe? As the code stands right now, isn't the value of "caching promises" entirely eliminated because we end up creating a new promise for every load call. So if 50k records all relate to the same record that means 50k promises, rather than 1. The trade-off for that loss is that we can re-use cache from an earlier call, but is that really used enough to warrant that behavior? The current code only provides value in the event we have a partially primed cache, where some objects are cached and others are not, ensuring that subsequent loads end up on the same tick. That feels like a pretty edgy-ish behavior that almost should be solved using different batch loading techniques.

主要言語
JavaScript
スター
13.4k
フォーク
522
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphql/dataloader のほかの issue

graphql/dataloader の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。