message: Optimize new-item calculation and take into account varying rolls
diff: @@ -7,7 +7,7 @@ import {
  import { D2Item } from '../inventory/item-types';
  import { D2Store } from '../inventory/store-types';
  import { D2ItemFetchRequest } from '../item-review/d2-dtr-api-types';
  -import { translateToDtrItem } from './d2-itemTransformer';
  +import { translateToDtrItem, getD2Roll } from './d2-itemTransformer';
  /**
  * Translate the universe of items that the user has in their stores into a collection of data that we can send the DTR API.
  @@ -49,20 +49,24 @@ export function getVendorItemList(
  function getNewItems(allItems: D2Item[], reviewDataCache: D2ReviewDataCache) {
  const allDtrItems = allItems.map(translateToDtrItem);
  - const allKnownDtrItems = reviewDataCache.getItemStores();
  + const allKnownDtrItems = new Set(
  + reviewDataCache.getItemStores().map((kdi) => `${kdi.referenceId}-${kdi.roll}`)
  + );
  - const unmatched = allDtrItems.filter((di) =>
  - allKnownDtrItems.every((kdi) => di.referenceId !== kdi.referenceId)
  + const unmatched = allDtrItems.filter(
  + (di) => !allKnownDtrItems.has(`${di.referenceId}-${getD2Roll(di.availablePerks)}`)
  );
  return unmatched;
  }
  function getNewVendorItems(vendorItems: D2ItemFetchRequest[], reviewDataCache: D2ReviewDataCache) {
  - const allKnownDtrItems = reviewDataCache.getItemStores();
  + const allKnownDtrItems = new Set(
  + reviewDataCache.getItemStores().map((kdi) => `${kdi.referenceId}-${kdi.roll}`)
  + );
  - const unmatched = vendorItems.filter((vi) =>
  - allKnownDtrItems.every((di) => di.referenceId !== vi.referenceId)
  + const unmatched = vendorItems.filter(
  + (di) => !allKnownDtrItems.has(`${di.referenceId}-${getD2Roll(di.availablePerks)}`)
  );
  return unmatched;
  @@ -73,21 +77,12 @@ function getNewVendorItems(vendorItems: D2ItemFetchRequest[], reviewDataCache: D
  * extracting all of the vendor items. If the interface is the same for both, this can go
  * away.
  */
  -function getAllItems(stores: D2Store[]): D2Item[] {
  - return _.flatMap(stores, (store) => store.items);
  +function getAllReviewableItems(stores: D2Store[]): D2Item[] {
  + return _.flatMap(stores, (store) => store.items.filter((item) => item.reviewable));
  }
  // Get all of the weapons from our stores in a DTR API-friendly format.
  function getDtrItems(stores: D2Store[], reviewDataCache: D2ReviewDataCache): D2ItemFetchRequest[] {
  - const allItems = getAllItems(stores);
  -
  - const allReviewableItems = allItems.filter((item) => item.reviewable);
  -
  - const newItems = getNewItems(allReviewableItems, reviewDataCache);
  -
  - if (reviewDataCache.getItemStores().length > 0) {
  - return newItems;
  - }
  -
  - return allReviewableItems.map(translateToDtrItem);
  + const allReviewableItems = getAllReviewableItems(stores);
  + return getNewItems(allReviewableItems, reviewDataCache);
  }
  