lint and correct cypher query code

This commit is contained in:
2025-12-03 10:42:32 +00:00
parent 64c6bd8bdd
commit c8fac06f24
3 changed files with 28 additions and 2 deletions

View File

@@ -167,7 +167,8 @@
"Bash(GOROOT=/home/mleku/go node run_wasm_tests.mjs:*)", "Bash(GOROOT=/home/mleku/go node run_wasm_tests.mjs:*)",
"Bash(./orly:*)", "Bash(./orly:*)",
"Bash(./orly -version:*)", "Bash(./orly -version:*)",
"Bash(./orly --version:*)" "Bash(./orly --version:*)",
"Bash(GOOS=js GOARCH=wasm go test:*)"
], ],
"deny": [], "deny": [],
"ask": [] "ask": []

View File

@@ -154,13 +154,22 @@ CREATE (e)-[:AUTHORED_BY]->(a)
paramName := fmt.Sprintf("eTag_%d", eTagIndex) paramName := fmt.Sprintf("eTag_%d", eTagIndex)
params[paramName] = tagValue params[paramName] = tagValue
// Add WITH clause before first OPTIONAL MATCH to transition from CREATE to MATCH // Add WITH clause before OPTIONAL MATCH
// This is required because:
// 1. Cypher doesn't allow MATCH after CREATE without WITH
// 2. Cypher doesn't allow MATCH after FOREACH without WITH
// So we need WITH before EVERY OPTIONAL MATCH, not just the first
if needsWithClause { if needsWithClause {
cypher += ` cypher += `
// Carry forward event and author nodes for tag processing // Carry forward event and author nodes for tag processing
WITH e, a WITH e, a
` `
needsWithClause = false needsWithClause = false
} else {
// After a FOREACH, we need WITH to transition back to MATCH
cypher += `
WITH e, a
`
} }
cypher += fmt.Sprintf(` cypher += fmt.Sprintf(`

View File

@@ -236,6 +236,7 @@ func (p *SocialEventProcessor) processReport(ctx context.Context, ev *event.E) e
} }
// Create REPORTS relationship // Create REPORTS relationship
// Note: WITH is required between CREATE and MERGE in Cypher
cypher := ` cypher := `
// Create event tracking node // Create event tracking node
CREATE (evt:ProcessedSocialEvent { CREATE (evt:ProcessedSocialEvent {
@@ -248,6 +249,9 @@ func (p *SocialEventProcessor) processReport(ctx context.Context, ev *event.E) e
superseded_by: null superseded_by: null
}) })
// WITH required to transition from CREATE to MERGE
WITH evt
// Create or get reporter and reported users // Create or get reporter and reported users
MERGE (reporter:NostrUser {pubkey: $reporter_pubkey}) MERGE (reporter:NostrUser {pubkey: $reporter_pubkey})
MERGE (reported:NostrUser {pubkey: $reported_pubkey}) MERGE (reported:NostrUser {pubkey: $reported_pubkey})
@@ -293,12 +297,15 @@ type UpdateContactListParams struct {
// updateContactListGraph performs atomic graph update for contact list changes // updateContactListGraph performs atomic graph update for contact list changes
func (p *SocialEventProcessor) updateContactListGraph(ctx context.Context, params UpdateContactListParams) error { func (p *SocialEventProcessor) updateContactListGraph(ctx context.Context, params UpdateContactListParams) error {
// Note: WITH is required between CREATE and MERGE in Cypher
cypher := ` cypher := `
// Mark old event as superseded (if exists) // Mark old event as superseded (if exists)
OPTIONAL MATCH (old:ProcessedSocialEvent {event_id: $old_event_id}) OPTIONAL MATCH (old:ProcessedSocialEvent {event_id: $old_event_id})
SET old.superseded_by = $new_event_id SET old.superseded_by = $new_event_id
// Create new event tracking node // Create new event tracking node
// WITH required after OPTIONAL MATCH + SET before CREATE
WITH old
CREATE (new:ProcessedSocialEvent { CREATE (new:ProcessedSocialEvent {
event_id: $new_event_id, event_id: $new_event_id,
event_kind: 3, event_kind: 3,
@@ -309,6 +316,9 @@ func (p *SocialEventProcessor) updateContactListGraph(ctx context.Context, param
superseded_by: null superseded_by: null
}) })
// WITH required to transition from CREATE to MERGE
WITH new
// Get or create author node // Get or create author node
MERGE (author:NostrUser {pubkey: $author_pubkey}) MERGE (author:NostrUser {pubkey: $author_pubkey})
@@ -369,12 +379,15 @@ type UpdateMuteListParams struct {
// updateMuteListGraph performs atomic graph update for mute list changes // updateMuteListGraph performs atomic graph update for mute list changes
func (p *SocialEventProcessor) updateMuteListGraph(ctx context.Context, params UpdateMuteListParams) error { func (p *SocialEventProcessor) updateMuteListGraph(ctx context.Context, params UpdateMuteListParams) error {
// Note: WITH is required between CREATE and MERGE in Cypher
cypher := ` cypher := `
// Mark old event as superseded (if exists) // Mark old event as superseded (if exists)
OPTIONAL MATCH (old:ProcessedSocialEvent {event_id: $old_event_id}) OPTIONAL MATCH (old:ProcessedSocialEvent {event_id: $old_event_id})
SET old.superseded_by = $new_event_id SET old.superseded_by = $new_event_id
// Create new event tracking node // Create new event tracking node
// WITH required after OPTIONAL MATCH + SET before CREATE
WITH old
CREATE (new:ProcessedSocialEvent { CREATE (new:ProcessedSocialEvent {
event_id: $new_event_id, event_id: $new_event_id,
event_kind: 10000, event_kind: 10000,
@@ -385,6 +398,9 @@ func (p *SocialEventProcessor) updateMuteListGraph(ctx context.Context, params U
superseded_by: null superseded_by: null
}) })
// WITH required to transition from CREATE to MERGE
WITH new
// Get or create author node // Get or create author node
MERGE (author:NostrUser {pubkey: $author_pubkey}) MERGE (author:NostrUser {pubkey: $author_pubkey})