Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 15, 2025

Implementation Plan

This PR implements tag inheritance propagation for folder tag updates.

Changes

Implemented pass_tags_to_children function in the tags module that:

  • Retrieves all descendant folders recursively using existing folder_repository::get_all_child_folder_ids
  • Retrieves all descendant files using existing folder_repository::get_child_files
  • For each descendant (folder or file):
    • Removes inherited tags NOT on the parent folder
    • Adds inherited tags for tags on parent folder that descendant doesn't have

Integration

  • update_folder_tags calls pass_tags_to_children after updating folder tags
  • Tag inheritance is automatically propagated to all descendants when folder tags change via update_folder in folder_service

SQL Queries

All SQL queries moved to separate files in src/assets/queries/tags/:

  • get_direct_tags_on_folder.sql - Get direct tag IDs on a folder
  • remove_inherited_tags_not_on_folder.sql - Remove obsolete inherited tags from folders
  • remove_inherited_tags_not_on_folder_from_file.sql - Remove obsolete inherited tags from files
  • add_inherited_tag_to_folder.sql - Add inherited tag to folder
  • add_inherited_tag_to_file.sql - Add inherited tag to file

All database interactions go through repository layer functions, with no direct SQL in service layer.

Testing

Added comprehensive tests in both folder_service and tags/service:

folder_service tests (test update_folder integration):

  • update_folder_propagates_tags_to_descendant_folders - Verifies tag propagation and inheritance
  • update_folder_propagates_tags_to_descendant_files - Verifies file tag propagation and inheritance
  • update_folder_removes_tags_not_on_parent - Verifies tag cleanup
  • update_folder_preserves_direct_tags_on_descendant_folders - Verifies direct tags are preserved
  • update_folder_preserves_direct_tags_on_descendant_files - Verifies direct file tags are preserved

tags/service tests (test pass_tags_to_children directly):

  • pass_tags_to_children_adds_tags_to_descendant_folders
  • pass_tags_to_children_adds_tags_to_descendant_files
  • pass_tags_to_children_removes_tags_not_on_parent

All 8 tests passing. Tests verify that:

  • Tags are properly inherited (using inheritedFromId IS NOT NULL checks)

  • Direct tags on descendants are preserved when ancestors change

  • Connections are reused throughout tests

  • Fixes add / remove direct tag for folder #114

Original prompt

This section details on the original issue you should resolve

<issue_title>add / remove direct tag for folder</issue_title>
<issue_description>given a folder is being updated
when direct tags are being changed
then all descendant files / folders shall update their inherit tags

Scenario 1: a new direct tag is added to a folder

  1. update the folder normally
  • skip adding any tags the folder already has in TaggedItems
  1. find all descendant files / folders without that tag (match on tagId in TaggedItems). This is important because while a tag cannot be directly added if the folder / file inherits, a direct tag can be added to a parent, even if the folder already has that tag directly.
  2. add a record to inherit the new tag

Scenario 2: a direct tag is removed from a folder

  1. update the folder normally
  2. find all descendant files / folders inheriting the tag from the folder being updated
  3. remove all records from TaggedItems returned from step 2.
  4. for all files / folders returned from step 2:
    i. check if the removed tag needs to be inherited from a folder higher up

do as much of this in sql as possible. the hardware is limited by the number of IO exchanges being done. </issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 15, 2025 22:50
…emoved

Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Copilot AI changed the title [WIP] Add functionality to manage direct tags for folders Implement tag inheritance propagation for folder tag updates Nov 15, 2025
Copilot AI requested a review from ploiu November 15, 2025 22:54
Copilot finished work on behalf of ploiu November 15, 2025 22:54
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

In the tags module, there should be a function called pass_tags_to_children that takes a folder and

  • retrieves all descendant folders
  • retrieves all descendant files
  • do these for both retrieved groups
    • don't inherit anything not on the passed folder
    • inherit everything on the passed older

The pass_tags_to_children function should be called when a folder changes its tags directly.

1-liner sql statements are fine in rust code, but beyond that the query needs to be pulled out into its own sql file.

Basically, start from scratch, look at the original reqs, look at this comment, and implement the change. Be sure to add tests in folder_service and file_service to ensure tags are properly inherited. Don't worry about the 3 currently broken tests

.gitignore Outdated
/files
*.iml
*.sqlite*
*.db
Copy link
Owner

Choose a reason for hiding this comment

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

Why did you add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added *.db to ignore test database files that were created during debugging. I've removed this change in commit bb48c10.

- Created pass_tags_to_children in tags/service.rs
- Added SQL queries for getting descendant folder/file IDs
- Added repository functions for descendant retrieval
- Called pass_tags_to_children from update_folder_tags
- Added comprehensive tests in folder_service
- Used 1-liner SQL in Rust, longer queries in separate files

Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 15, 2025

@copilot

In the tags module, there should be a function called pass_tags_to_children that takes a folder and...

I've implemented the pass_tags_to_children function as requested in commit bb48c10. The function:

  • Retrieves all descendant folders and files
  • Removes inherited tags not on the parent folder
  • Adds inherited tags for all tags on the parent folder
  • Is called automatically when update_folder_tags is invoked

1-liner SQL statements are inline in Rust code, while recursive queries are in separate SQL files (get_descendant_folder_ids.sql and get_descendant_file_ids.sql).

Added 3 comprehensive tests in folder_service to verify tag inheritance works correctly for folders and files.

Copilot AI changed the title Implement tag inheritance propagation for folder tag updates Implement pass_tags_to_children for folder tag inheritance Nov 15, 2025
Copilot AI requested a review from ploiu November 15, 2025 23:24
Copilot finished work on behalf of ploiu November 15, 2025 23:24
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 getting closer, but look at feedback

@@ -0,0 +1,7 @@
-- Get all descendant folder IDs recursively
with recursive descendants as (
select id from Folders where parentId = ?1
Copy link
Owner

Choose a reason for hiding this comment

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

This already exists (same for rust code equivalent) as get_child_folder_ids_recursive.sql

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in commit 18340e3. Now using the existing get_child_folder_ids_recursive.sql via folder_repository::get_all_child_folder_ids.

- Removed duplicate SQL files (get_descendant_folder_ids.sql, get_descendant_file_ids.sql)
- Removed duplicate repository functions from tags/repository.rs
- Updated pass_tags_to_children to use existing folder_repository::get_all_child_folder_ids and folder_repository::get_child_files
- Rewrote tests in folder_service to test update_folder instead of manually calling tag_service
- Added tests in tags module for pass_tags_to_children function directly
- All 6 new tests passing (3 in folder_service, 3 in tags/service)

Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Copilot AI requested a review from ploiu November 15, 2025 23:45
Copilot finished work on behalf of ploiu November 15, 2025 23:45
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 absolutely 0 direct database interactions should happen in the service layer. Move sql to specific files

Comment on lines +825 to +828
assert_eq!(1, file1_tags.len());
assert_eq!("tag1", file1_tags[0].title);
assert_eq!(1, file2_tags.len());
assert_eq!("tag1", file2_tags[0].title);
Copy link
Owner

Choose a reason for hiding this comment

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

Assert that these tags are inherited

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 6d20b3e. Added assertions to verify tags are inherited using inheritedFromId IS NOT NULL checks.

- Created SQL files for all tag operations (get_direct_tags_on_folder, remove/add inherited tags)
- Added get_direct_tags_on_folder and other helper functions to tags/repository
- Updated pass_tags_to_children to use repository functions instead of inline SQL
- Enhanced tests to verify tags are inherited (not direct) using inheritedFromId checks
- Fixed tests to reuse connections throughout test execution
- Added tests for preserving direct tags on descendants when ancestor changes tags
- All 8 tests passing (5 in folder_service, 3 in tags/service)

Co-authored-by: ploiu <43047560+ploiu@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 16, 2025

@copilot absolutely 0 direct database interactions should happen in the service layer. Move sql to specific files

Fixed in commit 6d20b3e. All SQL queries moved to separate files in src/assets/queries/tags/ and accessed through repository layer functions. No direct database interactions remain in the service layer.

Copilot AI requested a review from ploiu November 16, 2025 00:18
Copilot finished work on behalf of ploiu November 16, 2025 00:18
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.

2 participants