-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce the same interface across all ...Query
implementations
#5210
Enforce the same interface across all ...Query
implementations
#5210
Conversation
5a4e33c
to
b9c3f14
Compare
Hey, nice to see that you're picking up the work on I introduced the Generally, I agree that |
It's happy! mypy runs live in my editor as I code where it's allowed to control my implementation :) You've done an amazing job designing the generic types for |
b9c3f14
to
28a78d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, ok, so the point is that we don't really have any non-field query at this point. One could in principle imagine this: Maybe a query that involves several fields (although we also have the computed fields machinery, which might express that as well), or a plugin maintaining an extra table and defining a query on top of that. Thus, we don't need to accommodate for such queries at this point.
Looks good to me; I left a few notes where things might be improved or I'm not quite sure I understand why you coded things the way you did.
2c286fe
to
5276d04
Compare
...Query\
implementations...Query
implementations
@wisp3rwind you can see that I replaced Is there a reason we're using |
Lines 41 to 44 in 92fb830
|
Thanks! This may be slightly outdated (this was introduced ~8 years ago) or am I missing something? 🐶 beet list label:ᴄʟᴇʀɢʏ -f '$path'
/run/media/sarunas/music/Music/🔥/03_daxj_stealthmode.flac [ins] In [17]: db = sqlite3.connect("/home/sarunas/.music/beets/library.db")
[ins] In [18]: res = list(db.execute("select path from items where path = ?", ("/run/media/sarunas/music/Music/🔥/03_daxj_stealthmode.flac".encode(),)))
[ins] In [19]: res
Out[19]: [(b'/run/media/sarunas/music/Music/\xf0\x9f\x94\xa5/03_daxj_stealthmode.flac',)]
[ins] In [20]: res[0][0].decode()
Out[20]: '/run/media/sarunas/music/Music/🔥/03_daxj_stealthmode.flac' |
I really don't know. Is there any benefit to changing this? If at all possible, I'd prefer not to do so, at least not without a very good understanding of the original reasoning. Both to keep this PR focused, and because I'm afraid that this has the potential to break things in unexpected ways on different systems (with different OS, filesystem, terminal encodings). Note that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another, hopefully last, round of nitpicks :)
3e6e369
to
dddf090
Compare
While working on the DB optimisation I discovered one query which does not follow the 'FieldQuery' interface - 'PlaylistQuery', so I looked into it in more detail. One special thing about it is that it uses 'IN' SQL operator, so I defined 'InQuery' query class to have this logic outside of the playlist context. Otherwise, it seems like 'PlaylistQuery' is a field query, even if it has a very special way of resolving values it wants to query. In the future, we may want to consider moving this kind of custom _initialisation_ logic away from '__init__' methods to factory/@classmethod: this should make it more clear that the purpose of such logic is to resolve the data that is required to define a particular FieldQuery class fully.
Remove 'NamedQuery' since it is not being used by any queries any more. This simplifies query parsing logic in 'queryparse.py'. We know that this logic can only receive 'FieldQuery' thus I adjusted types and removed the logic that handles other cases. Effectively, this means that the query parsing logic does not any more care whether the query is named by the corresponding DB field. Instead, queries like 'SingletonQuery' and 'PlaylistQuery' are responsible for translating 'singleton' and 'playlist' to the underlying DB filters.
dddf090
to
b5e98b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, looks good to me now. Thanks 👍
Description
Make
PlaylistQuery
aFieldQuery
While working on the DB optimization and looking at updates upstream I discovered one query which does not follow the
FieldQuery
interface —PlaylistQuery
, so I looked into it in more detail and ended up integrating it as aFieldQuery
.One special thing about it is that it uses IN SQL operator, so I added implementation for this sort of query outside the playlist context, see
InQuery
.Otherwise, it seems like
PlaylistQuery
is a field query with a special way of resolving values it wants to query. In the future, we may want to consider moving this kind of custom initialization logic away frominit
methods to factory/@classmethod: this should make it more clear that the purpose of such logic is to resolve the data that is required to define a particularFieldQuery
class fully.Remove
NamedQuery
since it is unusedThis simplifies query parsing logic in
queryparse.py
. We know that this logic can only receiveFieldQuery
classes thus I adjusted types and removed the logic that handles other cases.Effectively, this means that the query parsing logic does not need to care whether the query is named by the corresponding DB field. Instead, queries like
SingletonQuery
andPlaylistQuery
are initialized with the same data as others and take things from there themselves: in this case they translatesingleton
andplaylist
queries to the underlying DB filters.