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

Commit ba5c79c

Browse files
committed
Stop hardcoding db index keys and change the format to not clash
1 parent c86a1c5 commit ba5c79c

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/GitHub.App/Caches/CacheIndex.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ namespace GitHub.Caches
1010
{
1111
public class CacheIndex
1212
{
13+
public const string PRPrefix = "index:pr";
14+
public const string RepoPrefix = "index:repos";
15+
public const string GitIgnoresPrefix = "index:ignores";
16+
public const string LicensesPrefix = "index:licenses";
17+
1318
public static CacheIndex Create(string key)
1419
{
1520
return new CacheIndex { IndexKey = key };

src/GitHub.App/Services/ModelService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ModelService(IApiClient apiClient, IBlobCache hostCache, IAvatarProvider
3939
public IObservable<GitIgnoreItem> GetGitIgnoreTemplates()
4040
{
4141
return Observable.Defer(() =>
42-
hostCache.GetAndFetchLatestFromIndex("global|ignores", () =>
42+
hostCache.GetAndFetchLatestFromIndex(CacheIndex.GitIgnoresPrefix, () =>
4343
GetGitIgnoreTemplatesFromApi(),
4444
item => { },
4545
TimeSpan.FromMinutes(1),
@@ -56,7 +56,7 @@ public IObservable<GitIgnoreItem> GetGitIgnoreTemplates()
5656
public IObservable<LicenseItem> GetLicenses()
5757
{
5858
return Observable.Defer(() =>
59-
hostCache.GetAndFetchLatestFromIndex("global|licenses", () =>
59+
hostCache.GetAndFetchLatestFromIndex(CacheIndex.LicensesPrefix, () =>
6060
GetLicensesFromApi(),
6161
item => { },
6262
TimeSpan.FromMinutes(1),
@@ -144,7 +144,7 @@ public ITrackingCollection<IPullRequestModel> GetPullRequests(ISimpleRepositoryM
144144
// and replaces it instead of appending, so items get refreshed in-place as they come in.
145145

146146
var keyobs = GetUserFromCache()
147-
.Select(user => string.Format(CultureInfo.InvariantCulture, "{0}|{1}|pr", user.Login, repo.Name));
147+
.Select(user => string.Format(CultureInfo.InvariantCulture, "{0}|{1}:{2}", CacheIndex.PRPrefix, user.Login, repo.Name));
148148

149149
var source = Observable.Defer(() => keyobs
150150
.SelectMany(key =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task CanRetrieveAndCacheGitIgnores()
7272
for (int i = 0; i < data.Length; i++)
7373
Assert.Equal(data[i], fetched[i].Name);
7474

75-
var indexKey = "global|ignores";
75+
var indexKey = CacheIndex.GitIgnoresPrefix;
7676
var cached = await cache.GetObject<CacheIndex>(indexKey);
7777
Assert.Equal(3, cached.Keys.Count);
7878

@@ -104,7 +104,7 @@ public async Task CanRetrieveAndCacheLicenses()
104104
for (int i = 0; i < data.Length; i++)
105105
Assert.Equal(data[i].Name, fetched[i].Name);
106106

107-
var indexKey = "global|licenses";
107+
var indexKey = CacheIndex.LicensesPrefix;
108108
var cached = await cache.GetObject<CacheIndex>(indexKey);
109109
Assert.Equal(2, cached.Keys.Count);
110110

0 commit comments

Comments
 (0)