-
Notifications
You must be signed in to change notification settings - Fork 318
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
added item_count #1492
base: main
Are you sure you want to change the base?
added item_count #1492
Conversation
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.
This is looking good to me!
I think two things need to be added here:
- a test for
item_count
, probably somewhere here:
async def test_get(jp_contents_manager): - a documentation entry in:
jupyter_server/docs/source/developers/contents.rst
Lines 34 to 38 in dd7daf9
Models may contain the following entries: +--------------------+------------+-------------------------------+ | Key | Type | Info | +====================+============+===============================+
and
jupyter_server/docs/source/developers/contents.rst
Lines 107 to 112 in dd7daf9
- ``directory`` models - The ``format`` field is always ``"json"``. - The ``mimetype`` field is always ``None``. - The ``content`` field contains a list of :ref:`content-free<contentfree>` models representing the entities in the directory. - The ``hash`` field is always ``None``.
I think this is fully backwards compatible but wanted to run it by @Zsailer to confirm.
@krassowski , I've changed tests and doc and ensured no tests are failing, ig its ready to be reviewed now |
Very good point! I just checked in two file managers (Nautilus and Nemo) and both do show the "1 item" if a folder includes both a hidden file and a non-hidden file by default, but if user selects "show hidden files" then they show "2 items". I wonder if there is a potential performance consideration here though.. |
For now I've added the filters to not count hidden files or any other file which are not visible on jupyter lab's file browser by default (which means item_count and len(contents) are equal), But yeah I otherwise need to somehow know if a user has selected show hidden folders in settings if yes then count those files too, not sure if it will cause any performance issues need to look into the code in more detail! Also noticed one more thing even after turning on show hidden folders in jupyter labs I was not able to see all files which were otherwise easily visible in files app, so I think it might not be necessary to add count of hidden folders or files especially if it may cause performance issues and can lead to inconsistent item counts and actual items visible though I can be completely wrong here |
This might add a performance hit to contents managers with a slow/remote filesystem (or just huge folder), as it will iterate over all directories for the current directory. There should at the very least be a way to turn this off via configuration. |
@vidartf, I agree with you and I'm not much familiar with jupyter server's code so just to confirm do you mean I should add something like this: count_directory_items = Bool(
True,
config=True,
help="Whether to count items in directories. Disable for better performance with large/remote directories."
).tag(config=True) in |
The discussion from last week's team meeting:
|
I do not understand why this constitutes a breaking change. I did not understand the statement during the meeting either, but I was the young contributor among a group of much more experienced maintainers so maybe I am missing something. This adds an optional element in the response. If we cannot extend our API anymore because each change is a breaking change, we should really rethink jupyter-server's core design. I am saying this because I feel like ideas for frontends enhancements are hitting the argument on backward compatibility across different PRs repeatedly, these are just three recent ones where I was somewhat involved:
For contrast, I understand why a similar statement was made about #1454 being backward incompatible, which was down to the following change: class FileContentsManager:
- def save(self, model, path=""):
+ def save(self, model, path="", require_hash=False):
"""Save the file model and return the model with no content.""" The logic there was: because users (in particular enterprise users) inherit/extend the Unfortunately, even using keyword-only arguments in parent class does not prevent subclasses from ignoring it: class A:
def save(self, model, *, path=""):
pass
class B(A):
def save(self, model, path="", oh_no_this_can_be_called_as_positional=1):
pass which means we need to sniff the arguments (or rethink the public API surface). I did not like how the introduction of
Agreed, but alternative contents managers do not need to return it
I do not see why this helps, it just moves the attribute around?
The idea of frontends needing to write a custom serrver extension to be able to populate data in file browser columns seems wrong to me. I don't think this should be maintained by frontends.
It would be interesting if jupyter-server supported pagination API. Then frontends could request:
|
Also, thank you @bollwyvl for summarising the meeting in the comment - I want to stress that I do not mean to shoot the messenger by using quotes from your comment, but I am trying to engage the arguments conveyed individually. |
Fixes #1491, This PR adds item_count