Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 200c29e

Browse files
committed
Only execute Update/Insert filters once in SaveAll APIs
1 parent 2e77643 commit 200c29e

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/ServiceStack.OrmLite/Async/OrmLiteWriteCommandExtensionsAsync.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ internal static async Task<int> SaveAllAsync<T>(this IDbCommand dbCmd, IEnumerab
415415
var id = modelDef.GetPrimaryKey(row);
416416
if (id != defaultIdValue && existingRowsMap.ContainsKey(id))
417417
{
418-
OrmLiteConfig.UpdateFilter?.Invoke(dbCmd, row);
419-
420418
await dbCmd.UpdateAsync(row, token, null);
421419
}
422420
else
@@ -430,8 +428,6 @@ internal static async Task<int> SaveAllAsync<T>(this IDbCommand dbCmd, IEnumerab
430428
}
431429
else
432430
{
433-
OrmLiteConfig.InsertFilter?.Invoke(dbCmd, row);
434-
435431
await dbCmd.InsertAsync(row, commandFilter:null, selectIdentity:false, token:token);
436432
}
437433

src/ServiceStack.OrmLite/OrmLiteWriteCommandExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,6 @@ internal static int SaveAll<T>(this IDbCommand dbCmd, IEnumerable<T> objs)
910910
var id = modelDef.GetPrimaryKey(row);
911911
if (id != defaultIdValue && existingRowsMap.ContainsKey(id))
912912
{
913-
OrmLiteConfig.UpdateFilter?.Invoke(dbCmd, row);
914913
dbCmd.Update(row);
915914
}
916915
else
@@ -925,7 +924,6 @@ internal static int SaveAll<T>(this IDbCommand dbCmd, IEnumerable<T> objs)
925924
}
926925
else
927926
{
928-
OrmLiteConfig.InsertFilter?.Invoke(dbCmd, row);
929927
dbCmd.Insert(row, commandFilter: null);
930928
}
931929

tests/ServiceStack.OrmLite.Tests/OrmLiteFiltersTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
24
using NUnit.Framework;
35
using ServiceStack.DataAnnotations;
6+
using ServiceStack.Text;
47

58
namespace ServiceStack.OrmLite.Tests
69
{
@@ -88,6 +91,33 @@ public void Does_call_Filters_on_insert_and_update()
8891
OrmLiteConfig.InsertFilter = OrmLiteConfig.UpdateFilter = null;
8992
}
9093

94+
[Test]
95+
public async Task Does_fire_filters_for_SaveAll()
96+
{
97+
var sbInsert = new List<string>();
98+
var sbUpdate = new List<string>();
99+
OrmLiteConfig.InsertFilter = (cmd, o) => sbInsert.Add(cmd.CommandText);
100+
OrmLiteConfig.UpdateFilter = (cmd, o) => sbUpdate.Add(cmd.CommandText);
101+
102+
using (var db = OpenDbConnection())
103+
{
104+
db.DropAndCreateTable<AuditTableA>();
105+
await db.SaveAllAsync(new[] {
106+
new AuditTableA {Id = 1, ModifiedBy = "A1"},
107+
new AuditTableA {Id = 2, ModifiedBy = "B1"},
108+
});
109+
110+
Assert.That(sbInsert.Count, Is.EqualTo(2));
111+
112+
await db.SaveAllAsync(new[] {
113+
new AuditTableA {Id = 1, ModifiedBy = "A2"},
114+
new AuditTableA {Id = 2, ModifiedBy = "B2"},
115+
});
116+
117+
Assert.That(sbUpdate.Count, Is.EqualTo(2));
118+
}
119+
}
120+
91121
[Test]
92122
public void Does_call_Filters_on_Save()
93123
{

0 commit comments

Comments
 (0)