refactor(dedup): unify identity key functions into buildIdentityKey#112
Open
retardgerman wants to merge 4 commits into
Open
refactor(dedup): unify identity key functions into buildIdentityKey#112retardgerman wants to merge 4 commits into
retardgerman wants to merge 4 commits into
Conversation
stableKeyFor() in roundupFirstSeen.js and buildIdentityKey() in libraryResolver.js both computed stable identifiers for Jellyfin items but used different key formats (m:tmdb:X vs movie:tmdb:X), making them incompatible and requiring parallel maintenance. buildIdentityKey() is now the single source of truth. Changes: - roundupFirstSeen.js imports buildIdentityKey from libraryResolver and removes stableKeyFor - buildIdentityKey gains IndexNumberEnd support for multi-episode ranges - PersistentMap gains rekey() and keys() to support the migration - A one-time startup migration converts v1 keys (m:/S:/s:/e: prefixes) to the v2 format so existing dedup state carries over without re-appearing as new content in the next Weekly Roundup
- Wrap migration IIFE in try/catch so a failure degrades gracefully instead of crashing the bot on startup - Move migrateKey() above the IIFE to remove a fragile hoisting dependency - Fix episode-range regex to preserve IndexNumberEnd during migration (e:SID-S1E1-3 now correctly migrates to series:id:SID:s1e1-3) - Use non-greedy .+? for SeriesId capture to handle dashed GUID formats - rekey() no longer overwrites an existing target entry; existing wins - keys() now evicts expired entries from memory, consistent with get/has - Log dropped keys at warn and migrated keys at info separately
- flush() now sets dirty=false only after renameSync succeeds, preventing a missed flush if the process is killed mid-write - rekey() logs at debug when a collision causes the old entry to be discarded, making migration collisions diagnosable in the field - Fix logger.warn in libraryResolver to interpolate the error message as a string instead of passing the Error object as a second argument
…Discord's 3s window Fetching full details (images, credits, external_ids) for up to 10 items in parallel inside the 3-second autocomplete deadline reliably causes DiscordAPIError[10062] Unknown interaction when TMDB is slow or the cache is cold. The search and trending endpoints already return title, year, and media_type — enough to build useful choices without any extra round-trips. Affects both /search and /trending autocomplete handlers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
stableKeyFor()inroundupFirstSeen.jsandbuildIdentityKey()inlibraryResolver.jsboth computed stable identifiers for Jellyfin items but used incompatible key formats (m:tmdb:Xvsmovie:tmdb:X). Any bug fix or logic change had to be made in both places independently, and the two systems could never be cross-referenced.buildIdentityKeyalso lacked support for multi-episode ranges (IndexNumberEnd), whichstableKeyForhandled.Fix
buildIdentityKeyis now the single source of truth for stable item identitystableKeyForremoved;roundupFirstSeen.jsimportsbuildIdentityKeydirectlybuildIdentityKeyextended withIndexNumberEndsupport for multi-episode entriesPersistentMapgainsrekey()andkeys()to enable key-format migrationm:,S:,s:,e:prefixes) to the v2 format so dedup state carries over without items re-appearing as new in the next Weekly Roundup