-
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
RFC: inline: make the album/item available directly #5439
base: master
Are you sure you want to change the base?
Conversation
Thank you for the PR! The changelog has not been updated, so here is a friendly reminder to check if you need to add an entry. |
It looks like there aren't any tests for the inline plugin at all right now, so I'll need to add a module for that to test this. It might be a couple days before I get to that. |
5b53ea6
to
df58c24
Compare
Updated to reformat with ruff and add the examples to the commit message to align with the PR description. |
df58c24
to
a92e317
Compare
Updated to add the changelog entry, and link to the missing plugin in the example in the docs. I thought about adding a direct example to the 'examples of expressions' in the inline docs, but the examples in the commit message are contrived, whereas the examples in the docs are more realistic. |
There have been multiple requests, in the past, for the ability to use plugin fields in inline fields. This has not previously been available. From what I can tell, it was intentionally left unavailable due to performance concerns. The way the item fields are made available to the inline python code means that all fields are looked up, whether they're actually used by the code or not. Doing that for all computed fields would be a performance concern. I don't believe there's a good way to postpone the field computation, as python eval and compile requires that globals be a dictionary, not a mapping. Instead, we can make available the album or item model object to the code directly, and let the code access the fields it needs via that object, resulting in postponing the computation of the fields until they're actually accessed. This is a simple approach that makes the computed and plugin fields available to inline python, which allows for more code reuse, as well as more options for shifting logic out of templates and into python code. In items, the object is available as 'item', and in albums, it's available as 'album'. Examples: item_fields: test_file_size: item.filesize album_fields: test_album_path: album.path # If the missing plugin is enabled test_album_missing: album.missing Signed-off-by: Christopher Larson <kergoth@gmail.com>
a92e317
to
8692b30
Compare
On second thought, this will break compatibility on the |
@sampsyo Any thoughts on this? I think this is probably the best method to make available computed fields without adding delays due to evaluating them all immediately, but I'm not sure on the best naming. |
Description
There have been multiple requests, in the past, for the ability to use plugin fields in inline fields. This has not previously been available. From what I can tell, it was intentionally left unavailable due to performance concerns.
The way the item fields are made available to the inline python code means that all fields are looked up, whether they're actually used by the code or not. Doing that for all computed fields would be a performance concern.
I don't believe there's a good way to postpone the field computation, as python eval and compile requires that globals be a dictionary, not a mapping. Instead, we can make available the album or item model object to the code directly, and let the code access the fields it needs via that object, resulting in postponing the computation of the fields until they're actually accessed.
This is a simple approach that makes the computed and plugin fields available to inline python, which allows for more code reuse, as well as more options for shifting logic out of templates and into python code.
In items, the object is available as 'item', and in albums, it's available as 'album'.
Examples:
To Do
docs/
to describe it.)docs/changelog.rst
to the bottom of one of the lists near the top of the document.)