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

    Function recordSearch

    • Tallies one completed search and the products it returned. Also backfills the install date, so counting starts even if the record was never seeded.

      Parameters

      • resultCount: number

        The number of products this search produced.

      Returns Promise<void>

      Resolves once the updated counters have been persisted.

      await recordSearch(42); // searchCount += 1, totalResults += 42
      
      export async function recordSearch(resultCount: number): Promise<void> {
      const state = await getReviewPromptState();
      const added = Number.isFinite(resultCount) && resultCount > 0 ? resultCount : 0;
      await cstorage.local.set({
      [CACHE.REVIEW_PROMPT]: {
      ...state,
      installedAt: state.installedAt > 0 ? state.installedAt : Date.now(),
      searchCount: state.searchCount + 1,
      totalResults: state.totalResults + added,
      },
      });
      }