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

Commit 0b9cae1

Browse files
authored
Merge pull request #668 from github/grokys/usagetracker-lazyload
Lazy load the services needed by UsageTracker.
2 parents 52b81db + c493e1e commit 0b9cae1

File tree

15 files changed

+124
-76
lines changed

15 files changed

+124
-76
lines changed

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System.Linq;
1818
using System.Reactive.Threading.Tasks;
1919
using System.Collections.Generic;
20+
using GitHub.Extensions;
2021

2122
namespace GitHub.Models
2223
{
@@ -241,7 +242,7 @@ IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
241242
if (result.IsSuccess())
242243
{
243244
var accountCacheItem = new AccountCacheItem(userAndScopes.User);
244-
usage.IncrementLoginCount();
245+
usage.IncrementLoginCount().Forget();
245246
return ModelService.InsertUser(accountCacheItem).Select(_ => result);
246247
}
247248

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async Task<IPullRequestModel> PushAndCreatePR(IRepositoryHost host,
9191
await Task.Delay(TimeSpan.FromSeconds(5));
9292

9393
var ret = await host.ModelService.CreatePullRequest(sourceRepository, targetRepository, sourceBranch, targetBranch, title, body);
94-
usageTracker.IncrementUpstreamPullRequestCount();
94+
await usageTracker.IncrementUpstreamPullRequestCount();
9595
return ret;
9696
}
9797

src/GitHub.App/ViewModels/GistCreationViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ IObservable<Gist> OnCreateGist(object unused)
7878
newGist.Files.Add(FileName, SelectedText);
7979

8080
return gistPublishService.PublishGist(apiClient, newGist)
81-
.Do(_ => usageTracker.IncrementCreateGistCount())
81+
.Do(_ => usageTracker.IncrementCreateGistCount().Forget())
8282
.Catch<Gist, Exception>(ex =>
8383
{
8484
if (!ex.IsCriticalException())

src/GitHub.App/ViewModels/RepositoryCloneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ IObservable<Unit> OnCloneRepository(object state)
161161
return cloneService.CloneRepository(repository.CloneUrl, repository.Name, BaseRepositoryPath)
162162
.ContinueAfter(() =>
163163
{
164-
usageTracker.IncrementCloneCount();
164+
usageTracker.IncrementCloneCount().Forget();
165165
return Observable.Return(Unit.Default);
166166
});
167167
})

src/GitHub.App/ViewModels/RepositoryCreationViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ IObservable<Unit> OnCreateRepository(object state)
268268
SelectedAccount,
269269
BaseRepositoryPath,
270270
repositoryHost.ApiClient)
271-
.Do(_ => usageTracker.IncrementCreateCount());
271+
.Do(_ => usageTracker.IncrementCreateCount().Forget());
272272
}
273273

274274
ReactiveCommand<Unit> InitializeCreateRepositoryCommand()

src/GitHub.App/ViewModels/RepositoryPublishViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ IObservable<ProgressState> OnPublishRepository(object arg)
153153
var account = SelectedAccount;
154154

155155
return repositoryPublishService.PublishRepository(newRepository, account, SelectedHost.ApiClient)
156-
.Do(_ => usageTracker.IncrementPublishCount())
156+
.Do(_ => usageTracker.IncrementPublishCount().Forget())
157157
.Select(_ => ProgressState.Success)
158158
.Catch<ProgressState, Exception>(ex =>
159159
{

src/GitHub.App/ViewModels/StartPageCloneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ IObservable<Unit> OnCloneRepository(object state)
105105
return cloneService.CloneRepository(repository.CloneUrl, repository.Name, BaseRepositoryPath)
106106
.ContinueAfter(() =>
107107
{
108-
usageTracker.IncrementCloneCount();
108+
usageTracker.IncrementCloneCount().Forget();
109109
return Observable.Return(Unit.Default);
110110
});
111111
})
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
using GitHub.VisualStudio;
22
using System.Runtime.InteropServices;
3+
using System.Threading.Tasks;
34

45
namespace GitHub.Services
56
{
67
[Guid(Guids.UsageTrackerId)]
78
public interface IUsageTracker
89
{
9-
void IncrementLaunchCount();
10-
void IncrementCloneCount();
11-
void IncrementCreateCount();
12-
void IncrementPublishCount();
13-
void IncrementOpenInGitHubCount();
14-
void IncrementLinkToGitHubCount();
15-
void IncrementCreateGistCount();
16-
void IncrementUpstreamPullRequestCount();
17-
void IncrementLoginCount();
10+
Task IncrementLaunchCount();
11+
Task IncrementCloneCount();
12+
Task IncrementCreateCount();
13+
Task IncrementPublishCount();
14+
Task IncrementOpenInGitHubCount();
15+
Task IncrementLinkToGitHubCount();
16+
Task IncrementCreateGistCount();
17+
Task IncrementUpstreamPullRequestCount();
18+
Task IncrementLoginCount();
1819
}
1920
}

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
<Compile Include="Properties\AssemblyInfo.cs" />
299299
<Compile Include="Helpers\Browser.cs" />
300300
<Compile Include="Services\UsageTracker.cs" />
301+
<Compile Include="Services\UsageTrackerDispatcher.cs" />
301302
<Compile Include="Settings\Constants.cs" />
302303
<Compile Include="Services\ConnectionManager.cs" />
303304
<Compile Include="Services\Program.cs" />

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
5252
await base.InitializeAsync(cancellationToken, progress);
5353
await EnsurePackageLoaded(new Guid(ServiceProviderPackage.ServiceProviderPackageId));
5454

55-
//var usageTracker = await GetServiceAsync(typeof(IUsageTracker)) as IUsageTracker;
56-
//usageTracker.IncrementLaunchCount();
55+
// Activate the usage tracker by forcing an instance to be created.
56+
GetServiceAsync(typeof(IUsageTracker)).Forget();
57+
5758
InitializeMenus().Forget();
5859
}
5960

@@ -178,6 +179,11 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
178179
var sp = await GetServiceAsync(typeof(IUIProvider)) as IUIProvider;
179180
return new MenuProvider(sp);
180181
}
182+
else if (serviceType == typeof(IUsageTracker))
183+
{
184+
var uiProvider = await GetServiceAsync(typeof(IUIProvider)) as IUIProvider;
185+
return new UsageTracker(uiProvider);
186+
}
181187
// go the mef route
182188
else
183189
{

0 commit comments

Comments
 (0)