Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 350f833

Browse files
committed
Delete *only* what is not in the new live data :P
1 parent 6ce0e4f commit 350f833

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/GitHub.App/Extensions/AkavacheExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static IObservable<T> GetAndFetchLatestFromIndex<T>(this IBlobCache This,
196196
.Do(x => index.AddAndSave(This, key, x, absoluteExpiration))
197197
.Finally(() =>
198198
{
199-
This.GetObjects<T>(index.OldKeys)
199+
This.GetObjects<T>(index.OldKeys.Except(index.Keys))
200200
.SelectMany(dict => dict.Values)
201201
.Do(item => removedItemsCallback(item))
202202
.Subscribe();

src/UnitTests/GitHub.App/Models/ModelServiceTests.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ public async Task ExpiredIndexClearsItems()
553553
indexobj.UpdatedAt = DateTimeOffset.UtcNow - TimeSpan.FromMinutes(6);
554554
await cache.InsertObject(indexKey, indexobj);
555555

556-
var prlive = Observable.Range(6, expected)
556+
var prlive = Observable.Range(5, expected)
557557
.Select(id => CreatePullRequest(user, id, ItemState.Open, "Live " + id, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, 0))
558558
.DelaySubscription(TimeSpan.FromMilliseconds(10));
559559

@@ -567,9 +567,10 @@ public async Task ExpiredIndexClearsItems()
567567
var evt = new ManualResetEvent(false);
568568
col.Subscribe(t =>
569569
{
570-
// we get all the items from the cache, all the items from the live,
571-
// and all the deletions because the cache expires old items when it's refreshed
572-
if (++count == expected * 3)
570+
// we get all the items from the cache (items 1-5), all the items from the live (items 5-9),
571+
// and 4 deletions (items 1-4) because the cache expired the items that were not
572+
// a part of the live data
573+
if (++count == 14)
573574
evt.Set();
574575
}, () => { });
575576

@@ -578,7 +579,13 @@ public async Task ExpiredIndexClearsItems()
578579
evt.Reset();
579580

580581
Assert.Equal(5, col.Count);
581-
Assert.Collection(col, col.Select(x => new Action<IPullRequestModel>(t => Assert.True(x.Title.StartsWith("Live")))).ToArray());
582+
Assert.Collection(col,
583+
t => { Assert.True(t.Title.StartsWith("Live")); Assert.Equal(5, t.Number); },
584+
t => { Assert.True(t.Title.StartsWith("Live")); Assert.Equal(6, t.Number); },
585+
t => { Assert.True(t.Title.StartsWith("Live")); Assert.Equal(7, t.Number); },
586+
t => { Assert.True(t.Title.StartsWith("Live")); Assert.Equal(8, t.Number); },
587+
t => { Assert.True(t.Title.StartsWith("Live")); Assert.Equal(9, t.Number); }
588+
);
582589
}
583590
}
584591

0 commit comments

Comments
 (0)