Skip to content

Commit e2448e0

Browse files
committed
Dry'ed EffectResults
1 parent 97c97ce commit e2448e0

1 file changed

Lines changed: 9 additions & 30 deletions

File tree

Core/Cleipnir.ResilientFunctions/Domain/EffectResults.cs

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,10 @@ await FlushOrAddToPending(
141141

142142
internal async Task Upsert<T>(EffectId effectId, string? alias, T value, bool flush)
143143
{
144-
var serializedValue = _serializer.Serialize(value!, typeof(T));
145-
var storedEffect = StoredEffect.CreateCompleted(effectId, serializedValue, alias);
146-
await FlushOrAddToPending(
147-
storedEffect.EffectId,
148-
storedEffect,
149-
flush,
150-
delete: false,
151-
clearChildren: false
152-
);
144+
FlushlessUpsert(effectId, alias, value);
145+
146+
if (flush)
147+
await Flush();
153148
}
154149

155150
internal void FlushlessUpsert<T>(EffectId effectId, string? alias, T value)
@@ -158,19 +153,10 @@ internal void FlushlessUpsert<T>(EffectId effectId, string? alias, T value)
158153
var storedEffect = StoredEffect.CreateCompleted(effectId, serializedValue, alias);
159154
AddToPending(storedEffect.EffectId, storedEffect, delete: false, clearChildren: false);
160155
}
161-
156+
162157
internal async Task Upserts(IEnumerable<EffectResult> values, bool flush)
163158
{
164-
var storedEffects = values
165-
.Select(t =>
166-
{
167-
var bytes = _serializer.Serialize(t.Value!, t.Value?.GetType() ?? typeof(object));
168-
return new { Id = t.Id, Bytes = bytes, Alias = t.Alias };
169-
})
170-
.Select(a => StoredEffect.CreateCompleted(a.Id, a.Bytes, a.Alias))
171-
.ToList();
172-
173-
AddToPending(storedEffects);
159+
FlushlessUpserts(values);
174160

175161
if (flush)
176162
await Flush();
@@ -400,19 +386,12 @@ await FlushOrAddToPending(
400386

401387
public async Task Clear(EffectId effectId, bool flush)
402388
{
403-
lock (_sync)
404-
if (_effectResults.ContainsKey(effectId))
405-
AddToPending(
406-
effectId,
407-
storedEffect: null,
408-
delete: true,
409-
clearChildren: true
410-
);
411-
389+
FlushlessClear(effectId);
390+
412391
if (flush)
413392
await Flush();
414393
}
415-
394+
416395
public void FlushlessClear(EffectId effectId)
417396
{
418397
lock (_sync)

0 commit comments

Comments
 (0)