Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 27, 2025

Addresses performance issues including N+1 queries, thread-safety bugs, and unnecessary object allocations.

Changes

  • Indexer.saveMusicAsync() - Fixed N+1 query problem by fetching all content IDs in single query, using HashSet for O(1) lookups, and batching saves (500/batch)

  • RetryService - Fixed thread-safety (was using shared mutable state), infinite loop when executor returns null, and improper interrupt handling

  • Indexer.filterPaths() - Replaced stream().anyMatch() per-path with simple for-loop

  • TorrentDownloadManager.startDownload() - Deduplicated torrent client creation logic

  • YoutubeCrawler - Made ObjectMapper static (thread-safe, expensive to create)

  • Indexer.createMusicEntities() - Parallelized to match createVideoEntities()

Example: N+1 fix

// Before: N queries
songs.stream()
    .filter(song -> !musicRepository.existsByContentId(song.getContentId()))

// After: 1 query + O(1) lookups
Set<String> existingIds = new HashSet<>(musicRepository.findAllContentIds());
songs.stream()
    .filter(song -> !existingIds.contains(song.getContentId()))
Original prompt

Identify and suggest improvements to slow or inefficient code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…essed

Co-authored-by: Brogrammer1912 <89769614+Brogrammer1912@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements for slow code Fix slow and inefficient code patterns Dec 27, 2025
Copilot AI requested a review from Brogrammer1912 December 27, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants