• Preloads common manga titles into the cache.

    Searches and caches frequently accessed titles to reduce subsequent API calls. Skips titles already in cache.

    Parameters

    • titles: string[]

      Array of manga titles to preload.

    • Optionaltoken: string

      Optional authentication token.

    • config: Partial<SearchServiceConfig> = {}

      Optional search service configuration overrides.

    Returns Promise<void>

    Promise resolving when preloading is complete.

    export async function preloadCommonManga(
    titles: string[],
    token?: string,
    config: Partial<SearchServiceConfig> = {},
    ): Promise<void> {
    console.info(
    `[MangaSearchService] 📥 Preloading ${titles.length} common manga titles...`,
    );
    const searchConfig = { ...DEFAULT_SEARCH_CONFIG, ...config };

    // Process in batches to respect rate limits
    let preloadedCount = 0;

    for (let i = 0; i < titles.length; i += searchConfig.batchSize) {
    const batch = titles.slice(i, i + searchConfig.batchSize);

    // Process batch items in sequence with rate limiting
    for (const title of batch) {
    const cacheKey = generateCacheKey(title);

    // Only search if not already in cache
    if (!isCacheValid(cacheKey)) {
    await searchMangaByTitle(title, token, searchConfig);
    preloadedCount++;
    }
    }
    }

    console.info(
    `[MangaSearchService] ✅ Preloading complete: ${preloadedCount} new titles cached`,
    );
    }