fix(library-desk): fix idempotency in create_entity_mentions
Fix create_entity_mentions to correctly count only newly created relationships, not all relationships processed by MERGE. **Problem**: count(r) was returning ALL relationships touched by MERGE (both created and matched), breaking idempotency tests. **Solution**: Use temporary flag 'just_created' set only ON CREATE, filter to those relationships, count them, then remove the flag. This ensures the count only includes new relationships. Now properly returns: - N on first run (N new relationships created) - 0 on subsequent runs (no new relationships, all already exist) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1158,11 +1158,16 @@ Feel free to expand it with more details!
|
||||
|
||||
// Create MENTIONS relationship if it doesn't exist
|
||||
MERGE (d)-[r:MENTIONS]->(e)
|
||||
ON CREATE SET r.created_at = datetime(),
|
||||
ON CREATE SET r.just_created = true,
|
||||
r.created_at = datetime(),
|
||||
r.mention_count = 1
|
||||
ON MATCH SET r.updated_at = datetime(),
|
||||
r.mention_count = COALESCE(r.mention_count, 0) + 1
|
||||
|
||||
// Count only newly created relationships
|
||||
WITH r
|
||||
WHERE r.just_created = true
|
||||
REMOVE r.just_created
|
||||
RETURN count(r) as relationships_created
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user