GeezerVison is showing github.com — Merge pull request #197 from olivierpaes/performance-streamid · SQLStreamStore/SQLStreamStore@3cd3929
This repository was archived by the owner on Aug 15, 2024. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStore.AppendStream.cs +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -131,7 +131,7 @@ private async Task<MsSqlAppendResult> AppendToStreamExpectedVersionAny( | 131 | 131 | { | 132 | 132 | using(var command = new SqlCommand(_scripts.AppendStreamExpectedVersionAny, connection, transaction)) | 133 | 133 | { | 134 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 134 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 135 | 135 | command.Parameters.AddWithValue("streamIdOriginal", sqlStreamId.IdOriginal); | 136 | 136 |
| 137 | 137 | if (messages.Any()) | @@ -236,7 +236,7 @@ private async Task<MsSqlAppendResult> AppendToStreamExpectedVersionNoStream( | 236 | 236 | { | 237 | 237 | using(var command = new SqlCommand(_scripts.AppendStreamExpectedVersionNoStream, connection, transaction)) | 238 | 238 | { | 239 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 239 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 240 | 240 | command.Parameters.AddWithValue("streamIdOriginal", sqlStreamId.IdOriginal); | 241 | 241 |
| 242 | 242 | if(messages.Length != 0) | @@ -343,7 +343,7 @@ private async Task<MsSqlAppendResult> AppendToStreamExpectedVersion( | 343 | 343 |
| 344 | 344 | using(var command = new SqlCommand(_scripts.AppendStreamExpectedVersion, connection, transaction)) | 345 | 345 | { | 346 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 346 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 347 | 347 | command.Parameters.AddWithValue("expectedStreamVersion", expectedVersion); | 348 | 348 | var eventsParam = CreateNewMessagesSqlParameter(sqlDataRecords); | 349 | 349 | command.Parameters.Add(eventsParam); | @@ -459,7 +459,7 @@ private async Task<int> GetStreamVersionOfMessageId( | 459 | 459 | { | 460 | 460 | using(var command = new SqlCommand(_scripts.GetStreamVersionOfMessageId, connection, transaction)) | 461 | 461 | { | 462 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 462 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 463 | 463 | command.Parameters.AddWithValue("messageId", messageId); | 464 | 464 |
| 465 | 465 | var result = await command.ExecuteScalarAsync(cancellationToken) | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStore.Delete.cs +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | namespace SqlStreamStore | 2 | 2 | { | 3 | 3 | using System; | | 4 | + using System.Data; | 4 | 5 | using System.Data.SqlClient; | 5 | 6 | using System.Threading; | 6 | 7 | using System.Threading.Tasks; | @@ -38,7 +39,7 @@ protected override async Task DeleteEventInternal( | 38 | 39 | bool deleted; | 39 | 40 | using (var command = new SqlCommand(_scripts.DeleteStreamMessage, connection, transaction)) | 40 | 41 | { | 41 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 42 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 42 | 43 | command.Parameters.AddWithValue("eventId", eventId); | 43 | 44 | var count = await command | 44 | 45 | .ExecuteScalarAsync(cancellationToken) | @@ -76,7 +77,7 @@ private async Task DeleteStreamExpectedVersion( | 76 | 77 | { | 77 | 78 | using(var command = new SqlCommand(_scripts.DeleteStreamExpectedVersion, connection, transaction)) | 78 | 79 | { | 79 | | - command.Parameters.AddWithValue("streamId", streamIdInfo.SqlStreamId.Id); | | 80 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamIdInfo.SqlStreamId.Id }); | 80 | 81 | command.Parameters.AddWithValue("expectedStreamVersion", expectedVersion); | 81 | 82 | try | 82 | 83 | { | @@ -142,7 +143,7 @@ private async Task DeleteStreamAnyVersion( | 142 | 143 | bool aStreamIsDeleted; | 143 | 144 | using (var command = new SqlCommand(_scripts.DeleteStreamAnyVersion, connection, transaction)) | 144 | 145 | { | 145 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 146 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 146 | 147 | var i = await command | 147 | 148 | .ExecuteScalarAsync(cancellationToken) | 148 | 149 | .NotOnCapturedContext(); | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStore.ReadStream.cs +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | { | 3 | 3 | using System; | 4 | 4 | using System.Collections.Generic; | | 5 | + using System.Data; | 5 | 6 | using System.Data.SqlClient; | 6 | 7 | using System.Linq; | 7 | 8 | using System.Threading; | @@ -107,7 +108,7 @@ private async Task<ReadStreamPage> ReadStreamInternal( | 107 | 108 |
| 108 | 109 | using (var command = new SqlCommand(commandText, connection, transaction)) | 109 | 110 | { | 110 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 111 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 111 | 112 | command.Parameters.AddWithValue("count", count + 1); //Read extra row to see if at end or not | 112 | 113 | command.Parameters.AddWithValue("streamVersion", streamVersion); | 113 | 114 |
| @@ -201,7 +202,7 @@ private async Task<string> GetJsonData(string streamId, int streamVersion, Cance | 201 | 202 | await connection.OpenAsync(cancellationToken).NotOnCapturedContext(); | 202 | 203 | using(var command = new SqlCommand(_scripts.ReadMessageData, connection)) | 203 | 204 | { | 204 | | - command.Parameters.AddWithValue("streamId", streamId); | | 205 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamId }); | 205 | 206 | command.Parameters.AddWithValue("streamVersion", streamVersion); | 206 | 207 |
| 207 | 208 | var jsonData = (string)await command.ExecuteScalarAsync(cancellationToken).NotOnCapturedContext(); | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStore.cs +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -211,7 +211,7 @@ protected override async Task<int> GetStreamMessageCount( | 211 | 211 | using(var command = new SqlCommand(_scripts.GetStreamMessageCount, connection)) | 212 | 212 | { | 213 | 213 | var streamIdInfo = new StreamIdInfo(streamId); | 214 | | - command.Parameters.AddWithValue("streamId", streamIdInfo.SqlStreamId.Id); | | 214 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamIdInfo.SqlStreamId.Id }); | 215 | 215 |
| 216 | 216 | var result = await command | 217 | 217 | .ExecuteScalarAsync(cancellationToken) | @@ -236,7 +236,7 @@ public async Task<int> GetmessageCount( | 236 | 236 | using (var command = new SqlCommand(_scripts.GetStreamMessageBeforeCreatedCount, connection)) | 237 | 237 | { | 238 | 238 | var streamIdInfo = new StreamIdInfo(streamId); | 239 | | - command.Parameters.AddWithValue("streamId", streamIdInfo.SqlStreamId.Id); | | 239 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamIdInfo.SqlStreamId.Id }); | 240 | 240 | command.Parameters.AddWithValue("created", createdBefore); | 241 | 241 |
| 242 | 242 | var result = await command | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStoreV3.AppendStream.cs +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -141,7 +141,7 @@ private async Task<MsSqlAppendResult> AppendToStreamExpectedVersionAny( | 141 | 141 | { | 142 | 142 | using(var command = new SqlCommand(_scripts.AppendStreamExpectedVersionAny, connection, transaction)) | 143 | 143 | { | 144 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 144 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 145 | 145 | command.Parameters.AddWithValue("streamIdOriginal", sqlStreamId.IdOriginal); | 146 | 146 |
| 147 | 147 | if (messages.Any()) | @@ -241,7 +241,7 @@ private async Task<MsSqlAppendResult> AppendToStreamExpectedVersionNoStream( | 241 | 241 | { | 242 | 242 | using(var command = new SqlCommand(_scripts.AppendStreamExpectedVersionNoStream, connection, transaction)) | 243 | 243 | { | 244 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 244 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 245 | 245 | command.Parameters.AddWithValue("streamIdOriginal", sqlStreamId.IdOriginal); | 246 | 246 |
| 247 | 247 | if(messages.Length != 0) | @@ -344,7 +344,7 @@ private async Task<MsSqlAppendResult> AppendToStreamExpectedVersion( | 344 | 344 |
| 345 | 345 | using(var command = new SqlCommand(_scripts.AppendStreamExpectedVersion, connection, transaction)) | 346 | 346 | { | 347 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 347 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 348 | 348 | command.Parameters.AddWithValue("expectedStreamVersion", expectedVersion); | 349 | 349 | var eventsParam = CreateNewMessagesSqlParameter(sqlDataRecords); | 350 | 350 | command.Parameters.Add(eventsParam); | @@ -453,7 +453,7 @@ private async Task<int> GetStreamVersionOfMessageId( | 453 | 453 | { | 454 | 454 | using(var command = new SqlCommand(_scripts.GetStreamVersionOfMessageId, connection, transaction)) | 455 | 455 | { | 456 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 456 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 457 | 457 | command.Parameters.AddWithValue("messageId", messageId); | 458 | 458 |
| 459 | 459 | var result = await command.ExecuteScalarAsync(cancellationToken) | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStoreV3.Delete.cs +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | namespace SqlStreamStore | 2 | 2 | { | 3 | 3 | using System; | | 4 | + using System.Data; | 4 | 5 | using System.Data.SqlClient; | 5 | 6 | using System.Threading; | 6 | 7 | using System.Threading.Tasks; | @@ -37,7 +38,7 @@ protected override async Task DeleteEventInternal( | 37 | 38 | bool deleted; | 38 | 39 | using (var command = new SqlCommand(_scripts.DeleteStreamMessage, connection, transaction)) | 39 | 40 | { | 40 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 41 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 41 | 42 | command.Parameters.AddWithValue("eventId", eventId); | 42 | 43 | var count = await command | 43 | 44 | .ExecuteScalarAsync(cancellationToken) | @@ -75,7 +76,7 @@ private async Task DeleteStreamExpectedVersion( | 75 | 76 | { | 76 | 77 | using(var command = new SqlCommand(_scripts.DeleteStreamExpectedVersion, connection, transaction)) | 77 | 78 | { | 78 | | - command.Parameters.AddWithValue("streamId", streamIdInfo.SqlStreamId.Id); | | 79 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamIdInfo.SqlStreamId.Id }); | 79 | 80 | command.Parameters.AddWithValue("expectedStreamVersion", expectedVersion); | 80 | 81 | try | 81 | 82 | { | @@ -144,7 +145,7 @@ private async Task DeleteStreamAnyVersion( | 144 | 145 | bool aStreamIsDeleted; | 145 | 146 | using (var command = new SqlCommand(_scripts.DeleteStreamAnyVersion, connection, transaction)) | 146 | 147 | { | 147 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 148 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 148 | 149 | var i = await command | 149 | 150 | .ExecuteScalarAsync(cancellationToken) | 150 | 151 | .NotOnCapturedContext(); | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStoreV3.ReadStream.cs +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 | { | 3 | 3 | using System; | 4 | 4 | using System.Collections.Generic; | | 5 | + using System.Data; | 5 | 6 | using System.Data.SqlClient; | 6 | 7 | using System.Linq; | 7 | 8 | using System.Threading; | @@ -101,7 +102,7 @@ protected override async Task<ReadStreamPage> ReadStreamBackwardsInternal( | 101 | 102 |
| 102 | 103 | using(var command = new SqlCommand(commandText, connection, transaction)) | 103 | 104 | { | 104 | | - command.Parameters.AddWithValue("streamId", sqlStreamId.Id); | | 105 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = sqlStreamId.Id }); | 105 | 106 | command.Parameters.AddWithValue("count", count + 1); //Read extra row to see if at end or not | 106 | 107 | command.Parameters.AddWithValue("streamVersion", streamVersion); | 107 | 108 |
| @@ -202,7 +203,7 @@ private async Task<string> GetJsonData(string streamId, int streamVersion, Cance | 202 | 203 | await connection.OpenAsync(cancellationToken).NotOnCapturedContext(); | 203 | 204 | using(var command = new SqlCommand(_scripts.ReadMessageData, connection)) | 204 | 205 | { | 205 | | - command.Parameters.AddWithValue("streamId", streamId); | | 206 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamId }); | 206 | 207 | command.Parameters.AddWithValue("streamVersion", streamVersion); | 207 | 208 |
| 208 | 209 | var jsonData = (string)await command.ExecuteScalarAsync(cancellationToken).NotOnCapturedContext(); | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStoreV3.StreamMetadata.cs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -88,7 +88,7 @@ protected override async Task<SetStreamMetadataResult> SetStreamMetadataInternal | 88 | 88 |
| 89 | 89 | using(var command = new SqlCommand(_scripts.SetStreamMetadata, connection, transaction)) | 90 | 90 | { | 91 | | - command.Parameters.AddWithValue("streamId", streamIdInfo.SqlStreamId.Id); | | 91 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamIdInfo.SqlStreamId.Id }); | 92 | 92 | command.Parameters.AddWithValue("streamIdOriginal", streamIdInfo.SqlStreamId.IdOriginal); | 93 | 93 | command.Parameters.Add("maxAge", SqlDbType.Int); | 94 | 94 | command.Parameters["maxAge"].Value = maxAge ?? -1; | |
Collapse file Copy file name to clipboardExpand all lines: src/SqlStreamStore.MsSql/MsSqlStreamStoreV3.cs +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -181,7 +181,7 @@ protected override async Task<int> GetStreamMessageCount( | 181 | 181 | using(var command = new SqlCommand(_scripts.GetStreamMessageCount, connection)) | 182 | 182 | { | 183 | 183 | var streamIdInfo = new StreamIdInfo(streamId); | 184 | | - command.Parameters.AddWithValue("streamId", streamIdInfo.SqlStreamId.Id); | | 184 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamIdInfo.SqlStreamId.Id }); | 185 | 185 |
| 186 | 186 | var result = await command | 187 | 187 | .ExecuteScalarAsync(cancellationToken) | @@ -206,7 +206,7 @@ public async Task<int> GetMessageCount( | 206 | 206 | using (var command = new SqlCommand(_scripts.GetStreamMessageBeforeCreatedCount, connection)) | 207 | 207 | { | 208 | 208 | var streamIdInfo = new StreamIdInfo(streamId); | 209 | | - command.Parameters.AddWithValue("streamId", streamIdInfo.SqlStreamId.Id); | | 209 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = streamIdInfo.SqlStreamId.Id }); | 210 | 210 | command.Parameters.AddWithValue("created", createdBefore); | 211 | 211 |
| 212 | 212 | var result = await command | @@ -294,7 +294,7 @@ await command | 294 | 294 |
| 295 | 295 | using(var command = new SqlCommand(_scripts.SetStreamMetadata, connection)) | 296 | 296 | { | 297 | | - command.Parameters.AddWithValue("streamId", new StreamIdInfo(streamId).SqlStreamId.Id); | | 297 | + command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42) { Value = new StreamIdInfo(streamId).SqlStreamId.Id }); | 298 | 298 | command.Parameters.AddWithValue("streamIdOriginal", "ignored"); | 299 | 299 | command.Parameters.Add("maxAge", SqlDbType.Int); | 300 | 300 | command.Parameters["maxAge"].Value = (object)metadata.MaxAge ?? DBNull.Value; | |
|