Skip to content

Conversation

brustolin
Copy link

@brustolin brustolin commented Aug 8, 2025

The previous code were trying to set the @StreamId variable that is not available in the query.
The @Limit @Skip variable is set inside the PagedEnumerationCollection iterator, so there is no need for a NextPageDelegate callback in here.

Fixes #54

@AGiorgetti AGiorgetti requested a review from Copilot August 8, 2025 13:06
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a crash in GetStreamsToSnapshot when handling result sets with more than 512 items by removing an invalid parameter assignment that referenced a non-existent @StreamId variable in the SQL query.

  • Removes the callback that was attempting to set an invalid @StreamId parameter
  • Simplifies the paged query execution by using an empty callback since the @Limit parameter is handled automatically

@@ -212,7 +212,7 @@ public virtual IEnumerable<IStreamHead> GetStreamsToSnapshot(string bucketId, in
query.AddParameter(_dialect.Threshold, maxThreshold);
return
query.ExecutePagedQuery(statement,
(q, s) => q.SetParameter(_dialect.StreamId, _dialect.CoalesceParameterValue(s.StreamId()), DbType.AnsiString)) // todo: I'm not sure this is used, the query does not have a "StreamId" parameter
(q, s) => { }) // There is no need for next page delegate in the Snapshot stream
Copy link
Preview

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

[nitpick] The comment should be more descriptive about why no next page delegate is needed. Consider: '// No next page delegate needed - @limit parameter is handled automatically by PagedEnumerationCollection'

Suggested change
(q, s) => { }) // There is no need for next page delegate in the Snapshot stream
(q, s) => { }) // No next page delegate needed - @Limit parameter is handled automatically by PagedEnumerationCollection

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

@copilot Can you double check if: "No next page delegate needed - @limit parameter is handled automatically by PagedEnumerationCollection" is true?

Copy link
Author

Choose a reason for hiding this comment

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

@AGiorgetti, sorry, my PR descriptions was wrong, its the @Skip variable that is handled by the PagedEnumerationCollection, but the behavior stills the same.

As you can see in the following code, the limit variable is set than _nextPage (the delegate) is called.

private bool MoveToNextRecord()
{
if (_pageSize > 0 && _position >= _pageSize)
{
_command.SetParameter(_dialect.Skip, _position);
if (_current is null)
{
throw new InvalidOperationException("Enumeration not started.");
}
_nextPage(_command, _current);
}

Copy link
Member

Choose a reason for hiding this comment

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

hi @brustolin , I was testing copilot review ability :) Is it possible to also add a test case in order to avoid future regression? Thanks.

Copy link
Author

Choose a reason for hiding this comment

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

@AGiorgetti I can try to add the tests, but I'm quite busy for a while, so it may take some time.

@AGiorgetti AGiorgetti assigned AGiorgetti and Copilot and unassigned AGiorgetti Aug 13, 2025
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.

GetStreamsToSnapshot for large database is crashing the Service
3 participants