mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
Optimizes the `subscribeVideos` callback in `js/services/nostrService.js` to handle video updates incrementally, avoiding O(N*M) complexity during high-volume updates (e.g., initial load). Changes: - Modified `js/nostr/videoEventBuffer.js` to include deleted videos in the flushed batch, allowing consumers to handle deletions incrementally. - Updated `js/services/nostrService.js` to process `updatedVideos` incrementally: - Separates updates into active and deleted. - Updates `this.videosMap` directly (removing deleted, adding/updating active). - Filters and caches only the active updates (O(M)). - Emits `videos:updated` with the full sorted list (derived from the updated map) to maintain API contract with consumers. - Persists the full sorted list to localStorage. This reduces the per-batch overhead significantly by avoiding O(N) filtering and map reconstruction for every batch of updates. Co-authored-by: PR0M3TH3AN <[email protected]>