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

Commit 5fe2916

Browse files
authored
Merge pull request #2055 from github/refactor/remove-trackingcollection
Remove trackingcollection
2 parents cdfbc34 + 95d4c0e commit 5fe2916

File tree

17 files changed

+57
-4447
lines changed

17 files changed

+57
-4447
lines changed

GitHubVS.sln

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Splat", "Splat", "{1E7F7253
7777
EndProject
7878
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CredentialManagement", "src\CredentialManagement\CredentialManagement.csproj", "{41A47C5B-C606-45B4-B83C-22B9239E4DA0}"
7979
EndProject
80-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrackingCollectionTests", "test\TrackingCollectionTests\TrackingCollectionTests.csproj", "{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}"
81-
EndProject
8280
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.TeamFoundation.14", "src\GitHub.TeamFoundation.14\GitHub.TeamFoundation.14.csproj", "{161DBF01-1DBF-4B00-8551-C5C00F26720D}"
8381
EndProject
8482
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.TeamFoundation.15", "src\GitHub.TeamFoundation.15\GitHub.TeamFoundation.15.csproj", "{161DBF01-1DBF-4B00-8551-C5C00F26720E}"
@@ -266,16 +264,6 @@ Global
266264
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.Release|Any CPU.Build.0 = Release|Any CPU
267265
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
268266
{41A47C5B-C606-45B4-B83C-22B9239E4DA0}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
269-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
270-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
271-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.DebugCodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
272-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.DebugCodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
273-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.DebugWithoutVsix|Any CPU.ActiveCfg = Debug|Any CPU
274-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.DebugWithoutVsix|Any CPU.Build.0 = Debug|Any CPU
275-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
276-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.Release|Any CPU.Build.0 = Release|Any CPU
277-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
278-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
279267
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
280268
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.Debug|Any CPU.Build.0 = Debug|Any CPU
281269
{161DBF01-1DBF-4B00-8551-C5C00F26720D}.DebugCodeAnalysis|Any CPU.ActiveCfg = DebugCodeAnalysis|Any CPU
@@ -568,7 +556,6 @@ Global
568556
{1E7F7253-A6AF-43C4-A955-37BEDDA01AB9} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
569557
{1E7F7253-A6AF-43C4-A955-37BEDDA01AC9} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
570558
{1E7F7253-A6AF-43C4-A955-37BEDDA01AF9} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
571-
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
572559
{110B206F-8554-4B51-BF86-94DAA32F5E26} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
573560
{17EB676B-BB91-48B5-AA59-C67695C647C2} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
574561
{C2D88962-BD6B-4F11-B914-535B38377962} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}

src/GitHub.App/Services/ModelService.cs

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -184,47 +184,6 @@ IObservable<AccountCacheItem> GetUserFromCache()
184184
return Observable.Defer(() => hostCache.GetObject<AccountCacheItem>("user"));
185185
}
186186

187-
/// <summary>
188-
/// Gets a collection of Pull Requests. If you want to refresh existing data, pass a collection in
189-
/// </summary>
190-
/// <param name="repo"></param>
191-
/// <param name="collection"></param>
192-
/// <returns></returns>
193-
public ITrackingCollection<IPullRequestModel> GetPullRequests(RepositoryModel repo,
194-
ITrackingCollection<IPullRequestModel> collection)
195-
{
196-
// Since the api to list pull requests returns all the data for each pr, cache each pr in its own entry
197-
// and also cache an index that contains all the keys for each pr. This way we can fetch prs in bulk
198-
// but also individually without duplicating information. We store things in a custom observable collection
199-
// that checks whether an item is being updated (coming from the live stream after being retrieved from cache)
200-
// and replaces it instead of appending, so items get refreshed in-place as they come in.
201-
202-
var keyobs = GetUserFromCache()
203-
.Select(user => string.Format(CultureInfo.InvariantCulture, "{0}|{1}:{2}", CacheIndex.PRPrefix, repo.Owner, repo.Name));
204-
205-
var source = Observable.Defer(() => keyobs
206-
.SelectMany(key =>
207-
hostCache.GetAndFetchLatestFromIndex(key, () =>
208-
ApiClient.GetPullRequestsForRepository(repo.CloneUrl.Owner, repo.CloneUrl.RepositoryName)
209-
.Select(PullRequestCacheItem.Create),
210-
item =>
211-
{
212-
if (collection.Disposed) return;
213-
214-
// this could blow up due to the collection being disposed somewhere else
215-
try { collection.RemoveItem(Create(item)); }
216-
catch (ObjectDisposedException) { }
217-
},
218-
TimeSpan.Zero,
219-
TimeSpan.FromDays(7))
220-
)
221-
.Select(Create)
222-
);
223-
224-
collection.Listen(source);
225-
return collection;
226-
}
227-
228187
public IObservable<IPullRequestModel> GetPullRequest(string owner, string name, int number)
229188
{
230189
throw new NotImplementedException();
@@ -243,34 +202,6 @@ public IObservable<RemoteRepositoryModel> GetRepository(string owner, string rep
243202
.Select(Create)));
244203
}
245204

246-
public ITrackingCollection<RemoteRepositoryModel> GetRepositories(ITrackingCollection<RemoteRepositoryModel> collection)
247-
{
248-
var keyobs = GetUserFromCache()
249-
.Select(user => string.Format(CultureInfo.InvariantCulture, "{0}|{1}", CacheIndex.RepoPrefix, user.Login));
250-
251-
var source = Observable.Defer(() => keyobs
252-
.SelectMany(key =>
253-
hostCache.GetAndFetchLatestFromIndex(key, () =>
254-
ApiClient.GetRepositories()
255-
.Select(RepositoryCacheItem.Create),
256-
item =>
257-
{
258-
if (collection.Disposed) return;
259-
260-
// this could blow up due to the collection being disposed somewhere else
261-
try { collection.RemoveItem(Create(item)); }
262-
catch (ObjectDisposedException) { }
263-
},
264-
TimeSpan.FromMinutes(5),
265-
TimeSpan.FromDays(1))
266-
)
267-
.Select(Create)
268-
);
269-
270-
collection.Listen(source);
271-
return collection;
272-
}
273-
274205
public IObservable<IPullRequestModel> CreatePullRequest(LocalRepositoryModel sourceRepository, RepositoryModel targetRepository,
275206
BranchModel sourceBranch, BranchModel targetBranch,
276207
string title, string body)

src/GitHub.App/ViewModels/Dialog/RepositoryCreationViewModel.cs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Linq;
88
using System.Reactive;
9+
using System.Reactive.Concurrency;
910
using System.Reactive.Linq;
1011
using System.Threading.Tasks;
1112
using System.Windows.Input;
@@ -176,7 +177,7 @@ public LicenseItem SelectedLicense
176177

177178
public async Task InitializeAsync(IConnection connection)
178179
{
179-
modelService = await modelServiceFactory.CreateAsync(connection);
180+
modelService = await modelServiceFactory.CreateAsync(connection).ConfigureAwait(true);
180181

181182
Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title);
182183

@@ -189,20 +190,34 @@ public async Task InitializeAsync(IConnection connection)
189190
.WhereNotNull()
190191
.Subscribe(a => SelectedAccount = a);
191192

192-
GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun(
193-
modelService.GetGitIgnoreTemplates(),
194-
new[] { GitIgnoreItem.None },
195-
OrderedComparer<GitIgnoreItem>.OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare,
196-
x =>
193+
modelService.GetGitIgnoreTemplates()
194+
.Where(x => x != null)
195+
.ToList()
196+
.ObserveOn(RxApp.MainThreadScheduler)
197+
.Subscribe(x =>
197198
{
198-
if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase))
199-
SelectedGitIgnoreTemplate = x;
199+
var sorted = x
200+
.Distinct()
201+
.OrderByDescending(item => item.Recommended)
202+
.ThenBy(item => item.Name);
203+
GitIgnoreTemplates = new[] { GitIgnoreItem.None }.Concat(sorted).ToList();
204+
205+
SelectedGitIgnoreTemplate = GitIgnoreTemplates
206+
.FirstOrDefault(i => i?.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase) == true);
200207
});
201208

202-
Licenses = TrackingCollection.CreateListenerCollectionAndRun(
203-
modelService.GetLicenses(),
204-
new[] { LicenseItem.None },
205-
OrderedComparer<LicenseItem>.OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare);
209+
modelService.GetLicenses()
210+
.Where(x => x != null)
211+
.ToList()
212+
.ObserveOn(RxApp.MainThreadScheduler)
213+
.Subscribe(x =>
214+
{
215+
var sorted = x
216+
.Distinct()
217+
.OrderByDescending(item => item.Recommended)
218+
.ThenBy(item => item.Key);
219+
Licenses = new[] { LicenseItem.None }.Concat(sorted).ToList();
220+
});
206221
}
207222

208223
protected override NewRepository GatherRepositoryInfo()

src/GitHub.Exports.Reactive/Collections/ITrackingCollection.cs

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)