Skip to content

Conversation

@bluepal-prasanthi-moparthi
Copy link
Collaborator

@bluepal-prasanthi-moparthi bluepal-prasanthi-moparthi commented Oct 3, 2025

Added len() method for collections CRUD operations

Closes: #686


Note

Adds Len() to collection CRUD response readers with caching, introduces shared ReadAll utilities, refactors readers to fix Old/New handling, and updates tests/benchmarks accordingly.

  • v2/arangodb (CRUD readers):
    • Add Len() to CollectionDocument*ResponseReader interfaces (create, read, update, replace, delete).
    • Implement caching in readers to support Len() while preserving Read() iteration.
    • Introduce shared.ReadAllReader and shared.ReadAllIntoReader utilities and wire them into readers.
    • Fix/optimize Old/New handling: per-item instance creation via cached reflect.Type and back-propagation to provided option objects.
  • Shared utilities:
    • New v2/arangodb/shared/read_all.go with generic ReadAll helpers for readers (with and without into-parameter).
  • Tests:
    • Update tests to use ReadAll(...), validate Len() behavior implicitly via caching, and assert meta.Old population for deletes.
    • Add bulk operation tests (create/read/update/replace) and adjust benchmarks to use ReadDocuments directly and minor setup cleanups.
  • Changelog:
    • Note addition of len() for Read methods under master.

Written by Cursor Bugbot for commit 4433ac8. This will update automatically on new commits. Configure here.

@cla-bot cla-bot bot added the cla-signed label Oct 3, 2025
@bluepal-prasanthi-moparthi bluepal-prasanthi-moparthi force-pushed the feature/add-getall-with-length branch 2 times, most recently from 084e9aa to 3a61ef3 Compare October 28, 2025 13:27
cursor[bot]

This comment was marked as outdated.

c.readIndex = 0 // Reset read position to allow Read() after Len()
}
return len(c.cachedResults)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Concurrent Access Causes Data Races

The Len() method modifies shared state (cached, cachedResults, cachedErrors, readIndex) without synchronization, creating race conditions when multiple goroutines call Len() or Read() concurrently on the same reader. The same reader instance could be accessed from multiple goroutines, causing data races and unpredictable behavior.

Fix in Cursor Fix in Web

c.readIndex = 0 // Reset read position to allow Read() after Len()
}
return len(c.cachedResults)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Concurrent Access Corrupts Shared Reader State

The Len() method modifies shared state (cached, cachedResults, cachedErrors, readIndex) without synchronization, creating race conditions when multiple goroutines call Len() or Read() concurrently on the same reader. The same reader instance could be accessed from multiple goroutines, causing data races and unpredictable behavior.

Fix in Cursor Fix in Web

c.readIndex = 0 // Reset read position to allow Read() after Len()
}
return len(c.cachedResults)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Race Conditions from Unsynchronized Shared State

The Len() method modifies shared state (cached, cachedResults, cachedErrors, readIndex) without synchronization, creating race conditions when multiple goroutines call Len() or Read() concurrently on the same reader. The same reader instance could be accessed from multiple goroutines, causing data races and unpredictable behavior.

Fix in Cursor Fix in Web

c.readIndex = 0 // Reset read position to allow Read() after Len()
}
return len(c.cachedResults)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Unsynchronized shared state leads to data races.

The Len() method modifies shared state (cached, cachedResults, cachedErrors, readIndex) without synchronization, creating race conditions when multiple goroutines call Len() or Read() concurrently on the same reader. The same reader instance could be accessed from multiple goroutines, causing data races and unpredictable behavior.

Fix in Cursor Fix in Web

c.readIndex = 0 // Reset read position to allow Read() after Len()
}
return len(c.cachedResults)
}
Copy link

Choose a reason for hiding this comment

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

Bug: Concurrency Bug: Unsynchronized Shared State

The Len() method modifies shared state (cached, cachedResults, cachedErrors, readIndex) without synchronization, creating race conditions when multiple goroutines call Len() or Read() concurrently on the same reader. The same reader instance could be accessed from multiple goroutines, causing data races and unpredictable behavior.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants