feat: search item by it's hash#478
Open
tikhonp wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds “hash query” shortcuts to the search endpoints so that when the query looks like an entity hash, results can be fetched directly from stores instead of doing fuzzy search.
Changes:
- Introduced hash-query detection (
HASH_QUERY_LENGTH) and helper methods to resolve tracks/artists/albums by hash. - Updated
search_tracks,search_artists, andsearch_albumsto short-circuit to hash lookups when applicable.
Comment on lines
+58
to
+69
| def _is_hash_query(self) -> bool: | ||
| return len(self.query) == HASH_QUERY_LENGTH | ||
|
|
||
| def _search_tracks_by_hash(self): | ||
| if not self._is_hash_query(): | ||
| return None | ||
|
|
||
| group = TrackStore.trackhashmap.get(self.query) | ||
| if group: | ||
| return group.tracks | ||
|
|
||
| return [] |
| def _is_hash_query(self) -> bool: | ||
| return len(self.query) == HASH_QUERY_LENGTH | ||
|
|
||
| def _search_tracks_by_hash(self): |
|
|
||
| return [] | ||
|
|
||
| def _search_artist_by_hash(self): |
|
|
||
| return [] | ||
|
|
||
| def _search_album_by_hash(self): |
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.
What kind of change does this PR introduce? (check at least one)
The PR fulfills these requirements:
fix #xxx[,#xxx], where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Initially, I needed an endpoint to get information about a single track by its hash, so I implemented an addition to the search functionality. Now, I can retrieve a song by hash not only through the API, but also via the web interface.
If you type the exact hash of a song, artist, or album, you will get that specific item; otherwise, the search behaves as usual.
P.S. I really love Swing Music for its simplicity and elegant interface, but without this feature, I’d have to maintain my own fork, which seems harder to manage in the long run. A merge would be highly appreciated.