ChemPal Documentation - v1.6.0
    Preparing search index...

    Function recordProductPrices

    • Record the current USD price of each product (and its variants) into the price-history store. A no-op when tracking is disabled. Fire-and-forget: the caller wraps this in void from the search flow. Only writes when a price changes, so repeated searches over cached results add nothing.

      Parameters

      • products: Product[]

        The products to record; each may carry variants.

      • Optionalsettings: PriceHistorySettings

        The user's price-history settings (trackPriceHistory, priceHistoryMaxPoints). Tracking is on unless explicitly disabled.

      Returns Promise<void>

      Resolves once all series have been processed.

      void recordProductPrices(finalResults, appContext.userSettings);
      
      export async function recordProductPrices(
      products: Product[],
      settings?: PriceHistorySettings,
      ): Promise<void> {
      if (settings?.trackPriceHistory === false) {
      return;
      }

      const maxPoints = normalizeMaxPoints(settings?.priceHistoryMaxPoints);
      const now = Date.now();

      for (const product of products) {
      for (const input of collectSeriesInputs(product)) {
      await recordSeries(input, maxPoints, now);
      }
      }
      }