Skip to content
This repository was archived by the owner on Feb 4, 2026. It is now read-only.

Remove stale ancestor implicit tags when folder is moved#131

Merged
ploiu merged 8 commits intotag_flatteningfrom
copilot/fix-folder-parentid-change
Nov 24, 2025
Merged

Remove stale ancestor implicit tags when folder is moved#131
ploiu merged 8 commits intotag_flatteningfrom
copilot/fix-folder-parentid-change

Conversation

Copy link
Contributor

Copilot AI commented Nov 24, 2025

Implementation Complete ✅

Successfully implemented folder move implicit tag recalculation feature with refactoring and comprehensive testing based on code review feedback.

Implementation Details:

  • Explore repository structure and understand the codebase
  • Build and test the project to confirm current state
  • Implement logic in update_folder to detect parent_id changes
  • When parent_id changes, retrieve original ancestors before database update
  • Remove implicit tags from descendants that were from old ancestors
  • Add test case: moving a folder to another folder recalculates descendant implicit tags
  • Add test case: moving a folder to root removes all descendant implicit tags from original ancestors
  • Add test case: moving folder does not remove tags from unaffected folders (siblings)
  • Add test case: moving folder does not remove explicit tags from descendants
  • Run tests and verify all pass (28/28 update_folder tests pass, 79/79 folder tests pass)
  • Refactor code based on review feedback
  • Fix bug affecting unaffected folders/files

Changes Made:

  1. Modified update_folder in src/service/folder_service.rs:

    • Added logic to detect when parent_id changes
    • Before database update: retrieve original ancestors using folder_repository::get_ancestor_folders_with_id
    • After database update: call handle_folder_move_for_tags to remove old ancestor implicit tags
  2. Added handle_folder_move_for_tags helper function:

    • Encapsulates the logic for removing implicit tags from descendants
    • Fixed critical bug: Now retrieves specific descendant folders and files, then selectively removes tags only from those items
    • Previously used bulk removal functions that incorrectly affected ALL items with the same implicit_from_id (including unaffected siblings)
    • Uses remove_implicit_tag_from_file and remove_implicit_tag_from_folder for targeted removal
  3. Added four comprehensive test cases:

    • moving_a_folder_to_another_folder_recalculates_descendant_implicit_tags: Verifies that moving a folder removes old ancestor implicit tags from descendants
    • moving_a_folder_to_root_removes_all_descendant_implicit_tags_from_original_ancestors: Verifies that moving to root removes all ancestor implicit tags
    • moving_folder_does_not_remove_tags_from_unaffected_folders: Verifies sibling folders keep their tags when another folder moves
    • moving_folder_does_not_remove_explicit_tags_from_descendants: Verifies explicit tags on descendants are preserved during move

Test Results:

  • All 28 update_folder tests pass ✅ (increased from 26 tests)
  • All 79 folder-related tests pass ✅
  • No existing functionality broken ✅
  • Edge cases verified: unaffected siblings, explicit tags, implicit tags

The implementation follows the minimal change principle, has been refactored based on code review feedback for better code organization, and includes comprehensive edge case testing to ensure correct behavior.

Original prompt

This section details on the original issue you should resolve

<issue_title>folder is moved</issue_title>
<issue_description>## Code
when it is requested that a folder's parentId changes (in folder_service::update_folder):

  • retrieve the original ancestors of the folder before the change is committed to the database (using folder_repository::get_ancestor_folders_with_id)
  • retrieve all descendant files and folders (using folder_repository::get_all_child_folder_ids and folder_repository::get_child_files)
  • for those descendants, remove all tags implicated by the old ancestor list

Tests

add these test cases for update folder

  • moving a folder to another folder recalculates descendant implicit tags
  • moving a folder to root removes all descendant implicit tags from original ancestors
    </issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Detect parent_id changes in update_folder
- Retrieve original ancestors before database update
- Remove implicit tags from descendants that came from old ancestors
- Add test: moving folder to another folder recalculates descendant implicit tags
- Add test: moving folder to root removes all descendant implicit tags

Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix folder parentId change handling for descendants Remove stale ancestor implicit tags when folder is moved Nov 24, 2025
Copilot AI requested a review from ploiu November 24, 2025 00:52
Copy link
Owner

@ploiu ploiu left a comment

Choose a reason for hiding this comment

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

@copilot

Comment on lines +193 to +204
match folder_repository::get_child_files(&all_folder_ids, &con) {
Ok(_files) => { /* retrieved successfully, we just needed to check */ }
Err(e) => {
log::error!(
"Failed to retrieve descendant files for folder {}. Error is {e:?}\n{}",
folder.id,
Backtrace::force_capture()
);
con.close().unwrap();
return Err(UpdateFolderError::DbFailure);
}
};
Copy link
Owner

Choose a reason for hiding this comment

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

What is the point of this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right - this check was unnecessary. The remove_implicit_tag_from_files and remove_implicit_tags_from_folders functions use the implicit_from_id (ancestor_id) to find and remove tags, not a list of file/folder IDs. Removed in commit a75399d.

- Move tag removal logic to new `handle_folder_move_for_tags` function
- Remove unnecessary file retrieval check that wasn't being used
- Repository functions already handle finding descendants automatically

Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Copilot AI requested a review from ploiu November 24, 2025 01:15
Copy link
Owner

@ploiu ploiu left a comment

Choose a reason for hiding this comment

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

@copilot

- Add test: moving_folder_does_not_remove_tags_from_unaffected_folders
- Add test: moving_folder_does_not_remove_explicit_tags_from_descendants
- Fix handle_folder_move_for_tags to only remove tags from moved folder's descendants
- Previously removed tags from ALL items with that implicit_from_id (affecting siblings)
- Now specifically targets only descendants of the moved folder

Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Copilot AI requested a review from ploiu November 24, 2025 01:31
@ploiu ploiu marked this pull request as ready for review November 24, 2025 18:07
@ploiu ploiu merged commit d6662aa into tag_flattening Nov 24, 2025
@ploiu ploiu deleted the copilot/fix-folder-parentid-change branch November 24, 2025 18:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants