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

Commit 2199169

Browse files
authored
Merge pull request #1449 from github/fixes/1319-crash-when-reading-old-data
Make sure we always create a valid index if the database has old/invalid json data
2 parents f10ea7d + ac16e66 commit 2199169

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/GitHub.App/Caches/CacheIndex.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static IObservable<CacheIndex> AddAndSaveToIndex(IBlobCache cache, string
6262
Guard.ArgumentNotNull(item, nameof(item));
6363

6464
return cache.GetOrCreateObject(indexKey, () => Create(indexKey))
65+
.Select(x => x.IndexKey == null ? Create(indexKey) : x)
6566
.Do(index =>
6667
{
6768
var k = string.Format(CultureInfo.InvariantCulture, "{0}|{1}", index.IndexKey, item.Key);

src/GitHub.App/Extensions/AkavacheExtensions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ static IObservable<T> GetAndFetchLatestFromIndex<T>(this IBlobCache This,
200200
bool shouldInvalidateOnError = false)
201201
where T : CacheItem
202202
{
203-
var idx = Observable.Defer(() => This.GetOrCreateObject(key, () => CacheIndex.Create(key))).Replay().RefCount();
203+
var idx = Observable.Defer(() => This
204+
.GetOrCreateObject(key, () => CacheIndex.Create(key)))
205+
.Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x)
206+
.Replay()
207+
.RefCount();
204208

205209

206210
var fetch = idx
@@ -264,6 +268,7 @@ public static IObservable<T> PutAndUpdateIndex<T>(this IBlobCache blobCache,
264268
{
265269
var absoluteExpiration = blobCache.Scheduler.Now + maxCacheDuration;
266270
return blobCache.GetOrCreateObject(key, () => CacheIndex.Create(key))
271+
.Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x)
267272
.SelectMany(index => fetchFunc()
268273
.Catch<T, Exception>(Observable.Throw<T>)
269274
.SelectMany(x => x.Save<T>(blobCache, key, absoluteExpiration))

0 commit comments

Comments
 (0)