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

Commit

Permalink
Merge pull request #1449 from github/fixes/1319-crash-when-reading-ol…
Browse files Browse the repository at this point in the history
…d-data

Make sure we always create a valid index if the database has old/invalid json data
  • Loading branch information
shana authored Feb 1, 2018
2 parents f10ea7d + ac16e66 commit 2199169
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/GitHub.App/Caches/CacheIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static IObservable<CacheIndex> AddAndSaveToIndex(IBlobCache cache, string
Guard.ArgumentNotNull(item, nameof(item));

return cache.GetOrCreateObject(indexKey, () => Create(indexKey))
.Select(x => x.IndexKey == null ? Create(indexKey) : x)
.Do(index =>
{
var k = string.Format(CultureInfo.InvariantCulture, "{0}|{1}", index.IndexKey, item.Key);
Expand Down
7 changes: 6 additions & 1 deletion src/GitHub.App/Extensions/AkavacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ static IObservable<T> GetAndFetchLatestFromIndex<T>(this IBlobCache This,
bool shouldInvalidateOnError = false)
where T : CacheItem
{
var idx = Observable.Defer(() => This.GetOrCreateObject(key, () => CacheIndex.Create(key))).Replay().RefCount();
var idx = Observable.Defer(() => This
.GetOrCreateObject(key, () => CacheIndex.Create(key)))
.Select(x => x.IndexKey == null ? CacheIndex.Create(key) : x)
.Replay()
.RefCount();


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

0 comments on commit 2199169

Please sign in to comment.