Skip to content

Clarify DatabaseServiceAdapter is temporary solution - #150

Merged
malibio merged 5 commits into
mainfrom
feature/issue-147-remove-database-adapter
Oct 5, 2025
Merged

malibio merged 5 commits into
mainfrom
feature/issue-147-remove-database-adapter

Conversation

@malibio

@malibio malibio commented Oct 5, 2025

Copy link
Copy Markdown
Collaborator

Closes #147

malibio and others added 3 commits October 5, 2025 18:50
Adds native queryNodes functionality to Rust backend, eliminating the need for
the temporary DatabaseServiceAdapter wrapper class in the frontend.

Backend changes:
- Add NodeQuery struct with builder methods for simple queries (id, mentionedBy,
  contentContains, nodeType, limit)
- Implement query_nodes_simple method in NodeService with priority-based query
  selection (id > mentionedBy > contentContains > nodeType)
- Add query_nodes_simple Tauri command and register it
- Export NodeQuery from nodespace_core

Frontend changes:
- Add queryNodes method to TauriNodeService with camelCase parameters
- Remove DatabaseServiceAdapter class entirely
- Update NodeReferenceService to use TauriNodeService directly
- Replace upsertNode with direct create/update logic
- Update all queryNodes calls to use camelCase (mentionedBy, contentContains,
  nodeType)

Test changes:
- Update MockTauriNodeService to match real TauriNodeService signature with
  camelCase parameters

Technical implementation:
- Uses SQLite JSON_EACH to efficiently query mentions arrays stored in
  properties.mentions
- Handles dynamic parameters with separate code paths for different query
  combinations to satisfy libsql's type requirements
- Maintains backward compatibility with existing query patterns

Closes #147

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…rvice

Removed outdated reference to MockDatabaseService in header comment and
updated to accurately reflect the use of TauriNodeService with native
backend queries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
**Changes:**

**Backend Architecture (Rust):**
- Added `mentions` and `mentioned_by` fields to Node struct
- Implemented bidirectional mention system using existing node_mentions table
- Added methods: add_mention(), remove_mention(), get_mentions(), get_mentioned_by()
- Updated get_node() to populate mentions from database
- Refactored query_nodes_simple() to use node_mentions table instead of JSON_EACH
- Added populate_mentions() helper method for efficient mention queries
- Added database index for JSON mentions (temporary performance fix)

**Code Quality:**
- Refactored duplicate content_contains query code
- Added 7 comprehensive unit tests for mentions functionality
- All 88 tests passing
- Fixed documentation example to use no_run annotation

**Performance Improvements:**
- Replaced inefficient JSON_EACH queries with direct table joins
- Index on mentions improves query performance

This addresses the architectural concern raised in PR review about mentions being stored in JSON properties. The backend now uses proper relational structure with the node_mentions table while maintaining backward compatibility. Frontend integration will be handled separately.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Oct 5, 2025

Copy link
Copy Markdown
Collaborator Author

Code Review Fixes Implemented

✅ Must-Fix Items (All Completed)

  1. Database Index for Mentions Query Performance ✓

    • Added index on json_extract(properties, '$.mentions')
    • Location: packages/core/src/db/database.rs:275-290
    • Note: This is a temporary optimization - proper solution implemented below
  2. Proper Mentions Architecture ✓

    • Implemented bidirectional mentions using existing node_mentions table
    • Added mentions and mentioned_by fields to Node struct
    • Replaced JSON_EACH queries with efficient table joins
    • New methods: add_mention(), remove_mention(), get_mentions(), get_mentioned_by()
    • Backend fully functional - frontend integration deferred per original plan
  3. Rust Unit Tests ✓

    • Added 7 comprehensive tests for mentions functionality
    • All 88 unit tests passing
    • Tests cover: add/remove, populate, query, duplicates, nonexistent nodes, bidirectional
  4. Code Refactoring ✓

    • Eliminated duplicate content_contains query code
    • Unified row processing logic
    • Added mentions population to all query paths

📋 Nice-to-Have Issues Created

Created 3 GitHub issues for future enhancements:

🧪 Test Results

All 88 unit tests passing:

cargo test --package nodespace-core --lib
test result: ok. 88 passed; 0 failed; 0 ignored

📝 Summary

This addresses the critical architectural concern about mentions being stored in JSON properties. The backend now uses proper relational structure with full bidirectional support. Frontend integration will happen in a future PR as originally planned.

Ready for re-review! 🚀

Added mentions and mentioned_by field initialization in create_node command
to match updated Node struct. Both fields start empty and are populated
by the database layer.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Documents the N+1 query pattern in populate_mentions() calls within
query_nodes_simple(). This is acceptable for current scale (<50 nodes
per query) but should be optimized with batch queries when usage grows.

Tracked in issue #163.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio
malibio merged commit 41690d0 into main Oct 5, 2025
@malibio
malibio deleted the feature/issue-147-remove-database-adapter branch October 5, 2025 17:52
malibio added a commit that referenced this pull request Feb 4, 2026
* Implement queryNodes in Rust backend and remove DatabaseServiceAdapter

Adds native queryNodes functionality to Rust backend, eliminating the need for
the temporary DatabaseServiceAdapter wrapper class in the frontend.

Backend changes:
- Add NodeQuery struct with builder methods for simple queries (id, mentionedBy,
  contentContains, nodeType, limit)
- Implement query_nodes_simple method in NodeService with priority-based query
  selection (id > mentionedBy > contentContains > nodeType)
- Add query_nodes_simple Tauri command and register it
- Export NodeQuery from nodespace_core

Frontend changes:
- Add queryNodes method to TauriNodeService with camelCase parameters
- Remove DatabaseServiceAdapter class entirely
- Update NodeReferenceService to use TauriNodeService directly
- Replace upsertNode with direct create/update logic
- Update all queryNodes calls to use camelCase (mentionedBy, contentContains,
  nodeType)

Test changes:
- Update MockTauriNodeService to match real TauriNodeService signature with
  camelCase parameters

Technical implementation:
- Uses SQLite JSON_EACH to efficiently query mentions arrays stored in
  properties.mentions
- Handles dynamic parameters with separate code paths for different query
  combinations to satisfy libsql's type requirements
- Maintains backward compatibility with existing query patterns

Closes #147

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix: Update NodeReferenceService documentation to reflect TauriNodeService

Removed outdated reference to MockDatabaseService in header comment and
updated to accurately reflect the use of TauriNodeService with native
backend queries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Implement proper mentions architecture using node_mentions table

**Changes:**

**Backend Architecture (Rust):**
- Added `mentions` and `mentioned_by` fields to Node struct
- Implemented bidirectional mention system using existing node_mentions table
- Added methods: add_mention(), remove_mention(), get_mentions(), get_mentioned_by()
- Updated get_node() to populate mentions from database
- Refactored query_nodes_simple() to use node_mentions table instead of JSON_EACH
- Added populate_mentions() helper method for efficient mention queries
- Added database index for JSON mentions (temporary performance fix)

**Code Quality:**
- Refactored duplicate content_contains query code
- Added 7 comprehensive unit tests for mentions functionality
- All 88 tests passing
- Fixed documentation example to use no_run annotation

**Performance Improvements:**
- Replaced inefficient JSON_EACH queries with direct table joins
- Index on mentions improves query performance

This addresses the architectural concern raised in PR review about mentions being stored in JSON properties. The backend now uses proper relational structure with the node_mentions table while maintaining backward compatibility. Frontend integration will be handled separately.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix Tauri create_node to include new mentions fields

Added mentions and mentioned_by field initialization in create_node command
to match updated Node struct. Both fields start empty and are populated
by the database layer.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Add TODO comments for N+1 query optimization

Documents the N+1 query pattern in populate_mentions() calls within
query_nodes_simple(). This is acceptable for current scale (<50 nodes
per query) but should be optimized with batch queries when usage grows.

Tracked in issue #163.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 5, 2026
* Implement queryNodes in Rust backend and remove DatabaseServiceAdapter

Adds native queryNodes functionality to Rust backend, eliminating the need for
the temporary DatabaseServiceAdapter wrapper class in the frontend.

Backend changes:
- Add NodeQuery struct with builder methods for simple queries (id, mentionedBy,
  contentContains, nodeType, limit)
- Implement query_nodes_simple method in NodeService with priority-based query
  selection (id > mentionedBy > contentContains > nodeType)
- Add query_nodes_simple Tauri command and register it
- Export NodeQuery from nodespace_core

Frontend changes:
- Add queryNodes method to TauriNodeService with camelCase parameters
- Remove DatabaseServiceAdapter class entirely
- Update NodeReferenceService to use TauriNodeService directly
- Replace upsertNode with direct create/update logic
- Update all queryNodes calls to use camelCase (mentionedBy, contentContains,
  nodeType)

Test changes:
- Update MockTauriNodeService to match real TauriNodeService signature with
  camelCase parameters

Technical implementation:
- Uses SQLite JSON_EACH to efficiently query mentions arrays stored in
  properties.mentions
- Handles dynamic parameters with separate code paths for different query
  combinations to satisfy libsql's type requirements
- Maintains backward compatibility with existing query patterns

Closes #147

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix: Update NodeReferenceService documentation to reflect TauriNodeService

Removed outdated reference to MockDatabaseService in header comment and
updated to accurately reflect the use of TauriNodeService with native
backend queries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Implement proper mentions architecture using node_mentions table

**Changes:**

**Backend Architecture (Rust):**
- Added `mentions` and `mentioned_by` fields to Node struct
- Implemented bidirectional mention system using existing node_mentions table
- Added methods: add_mention(), remove_mention(), get_mentions(), get_mentioned_by()
- Updated get_node() to populate mentions from database
- Refactored query_nodes_simple() to use node_mentions table instead of JSON_EACH
- Added populate_mentions() helper method for efficient mention queries
- Added database index for JSON mentions (temporary performance fix)

**Code Quality:**
- Refactored duplicate content_contains query code
- Added 7 comprehensive unit tests for mentions functionality
- All 88 tests passing
- Fixed documentation example to use no_run annotation

**Performance Improvements:**
- Replaced inefficient JSON_EACH queries with direct table joins
- Index on mentions improves query performance

This addresses the architectural concern raised in PR review about mentions being stored in JSON properties. The backend now uses proper relational structure with the node_mentions table while maintaining backward compatibility. Frontend integration will be handled separately.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix Tauri create_node to include new mentions fields

Added mentions and mentioned_by field initialization in create_node command
to match updated Node struct. Both fields start empty and are populated
by the database layer.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Add TODO comments for N+1 query optimization

Documents the N+1 query pattern in populate_mentions() calls within
query_nodes_simple(). This is acceptable for current scale (<50 nodes
per query) but should be optimized with batch queries when usage grows.

Tracked in issue #163.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
malibio added a commit that referenced this pull request Feb 26, 2026
* Implement queryNodes in Rust backend and remove DatabaseServiceAdapter

Adds native queryNodes functionality to Rust backend, eliminating the need for
the temporary DatabaseServiceAdapter wrapper class in the frontend.

Backend changes:
- Add NodeQuery struct with builder methods for simple queries (id, mentionedBy,
  contentContains, nodeType, limit)
- Implement query_nodes_simple method in NodeService with priority-based query
  selection (id > mentionedBy > contentContains > nodeType)
- Add query_nodes_simple Tauri command and register it
- Export NodeQuery from nodespace_core

Frontend changes:
- Add queryNodes method to TauriNodeService with camelCase parameters
- Remove DatabaseServiceAdapter class entirely
- Update NodeReferenceService to use TauriNodeService directly
- Replace upsertNode with direct create/update logic
- Update all queryNodes calls to use camelCase (mentionedBy, contentContains,
  nodeType)

Test changes:
- Update MockTauriNodeService to match real TauriNodeService signature with
  camelCase parameters

Technical implementation:
- Uses SQLite JSON_EACH to efficiently query mentions arrays stored in
  properties.mentions
- Handles dynamic parameters with separate code paths for different query
  combinations to satisfy libsql's type requirements
- Maintains backward compatibility with existing query patterns

Closes #147

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix: Update NodeReferenceService documentation to reflect TauriNodeService

Removed outdated reference to MockDatabaseService in header comment and
updated to accurately reflect the use of TauriNodeService with native
backend queries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Implement proper mentions architecture using node_mentions table

**Changes:**

**Backend Architecture (Rust):**
- Added `mentions` and `mentioned_by` fields to Node struct
- Implemented bidirectional mention system using existing node_mentions table
- Added methods: add_mention(), remove_mention(), get_mentions(), get_mentioned_by()
- Updated get_node() to populate mentions from database
- Refactored query_nodes_simple() to use node_mentions table instead of JSON_EACH
- Added populate_mentions() helper method for efficient mention queries
- Added database index for JSON mentions (temporary performance fix)

**Code Quality:**
- Refactored duplicate content_contains query code
- Added 7 comprehensive unit tests for mentions functionality
- All 88 tests passing
- Fixed documentation example to use no_run annotation

**Performance Improvements:**
- Replaced inefficient JSON_EACH queries with direct table joins
- Index on mentions improves query performance

This addresses the architectural concern raised in PR review about mentions being stored in JSON properties. The backend now uses proper relational structure with the node_mentions table while maintaining backward compatibility. Frontend integration will be handled separately.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Fix Tauri create_node to include new mentions fields

Added mentions and mentioned_by field initialization in create_node command
to match updated Node struct. Both fields start empty and are populated
by the database layer.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

* Add TODO comments for N+1 query optimization

Documents the N+1 query pattern in populate_mentions() calls within
query_nodes_simple(). This is acceptable for current scale (<50 nodes
per query) but should be optimized with batch queries when usage grows.

Tracked in issue #163.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
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.

Clarify DatabaseServiceAdapter is temporary solution

1 participant