Skip to content
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

Extend File.compare_by_size to use folder item count where appropriate #1978

Merged
merged 25 commits into from
Jun 6, 2023

Conversation

jeremypw
Copy link
Collaborator

@jeremypw jeremypw commented Jan 9, 2022

Fixes #1971
Fixes #2108

@jeremypw jeremypw marked this pull request as draft June 4, 2022 14:38
@jeremypw jeremypw added the Status: Blocked Cannot proceed until another issue is fixed label Jun 4, 2022
@jeremypw jeremypw removed the Status: Blocked Cannot proceed until another issue is fixed label Feb 19, 2023
@jeremypw
Copy link
Collaborator Author

Blocking PR was closed without merging.

# Conflicts fixed in:
#	libcore/File.vala
@jeremypw jeremypw marked this pull request as ready for review February 19, 2023 18:08
@jeremypw jeremypw requested a review from a team April 20, 2023 13:25
zeebok
zeebok previously approved these changes May 13, 2023
Copy link
Contributor

@zeebok zeebok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good. Seems straightforward enough to not test but if you'd like me to, let me know.

@jeremypw
Copy link
Collaborator Author

I would consider this complex enough to require at least some testing especially as it was written a while ago and has had master merged several times. I'll try it out again with some tests from the wiki.

@jeremypw
Copy link
Collaborator Author

One bug I notice in this is that the item count does not update when files are added (or removed) externally until the view is refreshed. I guess I should fix that.

@jeremypw jeremypw marked this pull request as draft May 13, 2023 12:58
@jeremypw
Copy link
Collaborator Author

I don't think there is a simple way of getting the number of items to update automatically - to do that we would have to put a monitor on every folder item.

@jeremypw
Copy link
Collaborator Author

jeremypw commented May 13, 2023

I have confirmed Nautilus behaves the same.

@jeremypw
Copy link
Collaborator Author

jeremypw commented May 13, 2023

Another slight quirk is that if a folder contains e.g. just one hidden file then the item count is "1" regardless of the "Show hidden" setting. So opening such a folder can result in the message "Empty" even though the item count is >0.
I have confirmed Nautilus behaves slightly differently - the item count remains at "1" until you enter the folder then come back out when it changes to "0". I am not sure this is any better.

On further investigation this behaviour only occurs if there is just one hidden file in the folder. If there are two files then the item count updates when "Show hidden is toggled". We should probably do the same.

@jeremypw
Copy link
Collaborator Author

Now only visible items are counted matching Nautilus's behaviour (without the bug).

@jeremypw jeremypw marked this pull request as ready for review May 13, 2023 16:16
@jeremypw
Copy link
Collaborator Author

@zeebok I have made some changes to this PR. I hope you do not mind having another look 😄

Copy link
Member

@danirabbit danirabbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one questions from me :)

libcore/File.vala Outdated Show resolved Hide resolved
Jeremy Wootten and others added 2 commits May 17, 2023 12:25
Co-authored-by: Danielle Foré <danielle@elementary.io>
@jeremypw jeremypw requested a review from ryonakano May 17, 2023 11:26
libcore/File.vala Outdated Show resolved Hide resolved
ensure_item_count (true); // Re-count file items

if (count < 0) {
return (_("—"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this string really need to be translatable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take your advice on this. Does that character have the required meaning in all scripts?

libcore/File.vala Outdated Show resolved Hide resolved
@ryonakano
Copy link
Contributor

Also, it feels strange for me that the item count won't be updated on file creation/deletion inside a folder unless we press Ctrl + R to trigger refresh.

Co-authored-by: Ryo Nakano <ryonakaknock3@gmail.com>
@jeremypw
Copy link
Collaborator Author

jeremypw commented May 18, 2023

Also, it feels strange for me that the item count won't be updated on file creation/deletion inside a folder unless we press Ctrl + R to trigger refresh.

I can probably get the count to update when the file operation is internal but it still will not if the operation is external.
I can confirm Nautilus does update on internal file operations and not external ones.

@jeremypw
Copy link
Collaborator Author

jeremypw commented May 18, 2023

After the last commit, the count updates after an internal change. It will also update after an external change if the changed folder is open in a tab, window or expanded in list view. It will not update if only being shown as an unexpanded item in a view because there is no Directory object to monitor for changes. This matches Nautilus' behaviour

Update: There are some operations like "Paste Into" where the item count is still not updated (but it is in Nautilus). A more complicated solution is needed to cover situations where there is no Directory object for the folder where the item count changes.

@jeremypw jeremypw requested a review from ryonakano May 18, 2023 17:30
@jeremypw
Copy link
Collaborator Author

We should perhaps consider whether we need to throttle the count updates when adding/removing large numbers of files in one operation else it will slow things up.

@jeremypw jeremypw marked this pull request as draft May 18, 2023 17:41
@jeremypw
Copy link
Collaborator Author

Converting to draft while investigating performance

Jeremy Wootten added 4 commits May 19, 2023 13:04
* Ignore duplicate operations (file already added to or removed from hash)
* Ignore CHANGES_DONE_HINT event avoids duplicate update
* Only update size once per set of changes if actually changed
* Assert each change set from same folder
* Simplify File.update_size and rename to ensure_size
@jeremypw
Copy link
Collaborator Author

jeremypw commented May 19, 2023

The latest commits improve performance by updating the count only once per batch of file changes. This assumes that each batch refer to the same folder - this needs testing thoroughly. It is certainly true for internally generated changes as the user can only interact with one background folder at a time but may not be true for external changes. Performance is also improved by only signalling the model(s) to add a file if it is not already in the directory file hash.

Also, folder item counts now update their count even if there is no Directory object for them. The Directory handling the change now also checks for a Directory object for the grandparent of the file and if it exists notifies that that its item count should update.

As before, external changes are only reflected in item counts if there is a Directory object corresponding to the altered folder (which monitors it).

@jeremypw jeremypw marked this pull request as ready for review May 19, 2023 18:27
@jeremypw
Copy link
Collaborator Author

jeremypw commented May 19, 2023

TESTING:

Try to generate a set of file changes where the files in the list do not have the same parent folder.

The item count of an unexpanded folder item in ListView should always update when its content is changed within the app e.g. in another tab or window howsoever that is done - cut and paste/paste into/drag and drop/undo and redo.

External changes should be reflected in the item count of an unexpanded ListView folder item if that folder is also open in another tab or window.

External changes should be reflected in the item count of an expanded ListView folder item.

Item counts should reflect the visible items - i.e. they should change when "Show hidden" is toggled according to whether the folder contains hidden files.

Copy link
Contributor

@zeebok zeebok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work when I did my testing and the code seems reasonable

@jeremypw jeremypw merged commit c0a70d7 into master Jun 6, 2023
@jeremypw jeremypw deleted the sort-folder-size branch June 6, 2023 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Files no longer shows size of folders in list view Sort by size has no effect on folders.
4 participants