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

Commit 3900a41

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/metrics
2 parents dcc31fd + d6adf32 commit 3900a41

File tree

97 files changed

+1409
-820
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1409
-820
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
[submodule "submodules/akavache"]
1414
path = submodules/akavache
1515
url = https://github.com/shana/Akavache
16-
[submodule "submodules/libgit2sharp"]
17-
path = submodules/libgit2sharp
18-
url = https://github.com/shana/libgit2sharp.git
1916
[submodule "script"]
2017
path = script
2118
url = [email protected]:github/VisualStudioBuildScripts

GitHubVS.sln

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Submodules", "Submodules",
2626
EndProject
2727
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rothko", "submodules\Rothko\src\Rothko.csproj", "{4A84E568-CA86-4510-8CD0-90D3EF9B65F9}"
2828
EndProject
29-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LibGit2Sharp", "LibGit2Sharp", "{8446C785-A5B4-4676-9B38-560FCA0563E0}"
30-
EndProject
31-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibGit2Sharp", "submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}"
32-
EndProject
3329
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{8E1F1B4E-AEA2-4AB1-8F73-423A903550A1}"
3430
ProjectSection(SolutionItems) = preProject
3531
script\Modules\BuildUtils.psm1 = script\Modules\BuildUtils.psm1
@@ -246,22 +242,6 @@ Global
246242
{4A84E568-CA86-4510-8CD0-90D3EF9B65F9}.XamlDesign|Any CPU.Build.0 = Release|Any CPU
247243
{4A84E568-CA86-4510-8CD0-90D3EF9B65F9}.XamlDesign|x86.ActiveCfg = Release|Any CPU
248244
{4A84E568-CA86-4510-8CD0-90D3EF9B65F9}.XamlDesign|x86.Build.0 = Release|Any CPU
249-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
250-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.Build.0 = Debug|Any CPU
251-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|x86.ActiveCfg = Debug|Any CPU
252-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|x86.Build.0 = Debug|Any CPU
253-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Publish|Any CPU.ActiveCfg = Release|Any CPU
254-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Publish|Any CPU.Build.0 = Release|Any CPU
255-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Publish|x86.ActiveCfg = Release|Any CPU
256-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Publish|x86.Build.0 = Release|Any CPU
257-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.ActiveCfg = Release|Any CPU
258-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|Any CPU.Build.0 = Release|Any CPU
259-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|x86.ActiveCfg = Release|Any CPU
260-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Release|x86.Build.0 = Release|Any CPU
261-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.XamlDesign|Any CPU.ActiveCfg = Debug|Any CPU
262-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.XamlDesign|Any CPU.Build.0 = Debug|Any CPU
263-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.XamlDesign|x86.ActiveCfg = Debug|Any CPU
264-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.XamlDesign|x86.Build.0 = Debug|Any CPU
265245
{9AEA02DB-02B5-409C-B0CA-115D05331A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
266246
{9AEA02DB-02B5-409C-B0CA-115D05331A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
267247
{9AEA02DB-02B5-409C-B0CA-115D05331A6B}.Debug|x86.ActiveCfg = Debug|Any CPU
@@ -587,8 +567,6 @@ Global
587567
GlobalSection(NestedProjects) = preSolution
588568
{596595A6-2A3C-469E-9386-9E3767D863A5} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
589569
{4A84E568-CA86-4510-8CD0-90D3EF9B65F9} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
590-
{8446C785-A5B4-4676-9B38-560FCA0563E0} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}
591-
{EE6ED99F-CB12-4683-B055-D28FC7357A34} = {8446C785-A5B4-4676-9B38-560FCA0563E0}
592570
{8E1F1B4E-AEA2-4AB1-8F73-423A903550A1} = {7B6C5F8D-14B3-443D-B044-0E209AE12BDF}
593571
{1ED83084-2A57-4F89-915C-8A2167C0D6BC} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFF}
594572
{1E7F7253-A6AF-43C4-A955-37BEDDA01AC0} = {1E7F7253-A6AF-43C4-A955-37BEDDA01AB8}

src/GitHub.App/Caches/CacheIndex.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ public CacheIndex()
2121
OldKeys = new List<string>();
2222
}
2323

24+
public CacheIndex Add(string indexKey, CacheItem item)
25+
{
26+
var k = string.Format(CultureInfo.InvariantCulture, "{0}|{1}", IndexKey, item.Key);
27+
if (!Keys.Contains(k))
28+
Keys.Add(k);
29+
UpdatedAt = DateTimeOffset.UtcNow;
30+
return this;
31+
}
32+
2433
public IObservable<CacheIndex> AddAndSave(IBlobCache cache, string indexKey, CacheItem item,
2534
DateTimeOffset? absoluteExpiration = null)
2635
{
@@ -29,7 +38,7 @@ public IObservable<CacheIndex> AddAndSave(IBlobCache cache, string indexKey, Cac
2938
Keys.Add(k);
3039
UpdatedAt = DateTimeOffset.UtcNow;
3140
return cache.InsertObject(IndexKey, this, absoluteExpiration)
32-
.Select(x => this);
41+
.Select(x => this);
3342
}
3443

3544
public static IObservable<CacheIndex> AddAndSaveToIndex(IBlobCache cache, string indexKey, CacheItem item,
@@ -47,15 +56,19 @@ public static IObservable<CacheIndex> AddAndSaveToIndex(IBlobCache cache, string
4756
.Select(x => index));
4857
}
4958

50-
public IObservable<CacheIndex> Clear(IBlobCache cache, string indexKey, DateTimeOffset? absoluteExpiration = null)
59+
public CacheIndex Clear()
5160
{
5261
OldKeys = Keys.ToList();
5362
Keys.Clear();
5463
UpdatedAt = DateTimeOffset.UtcNow;
55-
return cache
56-
.InvalidateObject<CacheIndex>(indexKey)
57-
.SelectMany(_ => cache.InsertObject(indexKey, this, absoluteExpiration))
58-
.Select(_ => this);
64+
return this;
65+
}
66+
67+
public IObservable<CacheIndex> Save(IBlobCache cache,
68+
DateTimeOffset? absoluteExpiration = null)
69+
{
70+
return cache.InsertObject(IndexKey, this, absoluteExpiration)
71+
.Select(x => this);
5972
}
6073

6174
[AllowNull]

src/GitHub.App/Caches/ImageCache.cs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -213,33 +213,8 @@ static string GetCacheKey(Uri url)
213213
return url.ToString();
214214
}
215215

216-
bool disposed;
217-
void Dispose(bool disposing)
218-
{
219-
if (disposing)
220-
{
221-
if (disposed) return;
222-
223-
try
224-
{
225-
cacheFactory.Select(x =>
226-
{
227-
x.Dispose();
228-
return x.Shutdown;
229-
}).Wait();
230-
}
231-
catch (Exception e)
232-
{
233-
log.Warn("Exception occured while disposing ImageCache", e);
234-
}
235-
disposed = true;
236-
}
237-
}
238-
239216
public void Dispose()
240-
{
241-
Dispose(true);
242-
}
217+
{}
243218

244219
class UriComparer : IEqualityComparer<Uri>
245220
{

src/GitHub.App/Caches/LoginCache.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,7 @@ public IObservable<Unit> Flush()
5656
return cache.Secure.Flush();
5757
}
5858

59-
bool disposed;
60-
void Dispose(bool disposing)
61-
{
62-
if (disposing)
63-
{
64-
if (disposed) return;
65-
66-
try
67-
{
68-
cache.Dispose();
69-
}
70-
catch (Exception e)
71-
{
72-
log.Warn("Exception occurred while disposing shared cache", e);
73-
}
74-
disposed = true;
75-
}
76-
}
77-
7859
public void Dispose()
79-
{
80-
Dispose(true);
81-
}
60+
{}
8261
}
8362
}

src/GitHub.App/Controllers/UIController.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ void End(bool success)
601601
ShutdownFlow(activeFlow);
602602

603603
// if the auth was cancelled, we need to stop everything, otherwise we'll go into a loop
604-
if (activeFlow == mainFlow || (activeFlow == UIControllerFlow.Authentication && !Success.Value))
604+
if (activeFlow == mainFlow || !Success.Value)
605605
stopping = true;
606606

607607
Fire(Trigger.Next);
@@ -736,16 +736,21 @@ bool CreateViewAndViewModel(UIViewType viewType, ViewWithData data = null)
736736
}
737737
}
738738

739-
if (!list.ContainsKey(viewType))
739+
IUIPair pair = null;
740+
var firstTime = !list.TryGetValue(viewType, out pair);
741+
742+
if (firstTime)
743+
pair = factory.CreateViewAndViewModel(viewType);
744+
745+
pair.ViewModel.Initialize(data);
746+
747+
if (firstTime)
740748
{
741-
var d = factory.CreateViewAndViewModel(viewType);
742-
d.ViewModel.Initialize(data);
743-
d.View.DataContext = d.ViewModel;
744-
list.Add(viewType, d);
745-
return true;
749+
pair.View.DataContext = pair.ViewModel;
750+
list.Add(viewType, pair);
746751
}
747752

748-
return false;
753+
return firstTime;
749754
}
750755

751756

@@ -834,6 +839,7 @@ public void Dispose()
834839

835840
public bool IsStopped => uiStateMachine.IsInState(UIViewType.None) || stopping;
836841
public UIControllerFlow CurrentFlow => activeFlow;
842+
public UIControllerFlow SelectedFlow => mainFlow;
837843
bool LoggedIn => connection != null && hosts.LookupHost(connection.HostAddress).IsLoggedIn;
838844
bool? Success { get; set; }
839845
}

src/GitHub.App/Extensions/AkavacheExtensions.cs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Reactive.Linq;
55
using Akavache;
66
using GitHub.Caches;
7+
using System.Threading.Tasks;
78

89
namespace GitHub.Extensions
910
{
@@ -199,39 +200,45 @@ static IObservable<T> GetAndFetchLatestFromIndex<T>(this IBlobCache This,
199200
bool shouldInvalidateOnError = false)
200201
where T : CacheItem
201202
{
202-
var fetch = Observable.Defer(() => This.GetOrCreateObject(key, () => CacheIndex.Create(key))
203+
var idx = Observable.Defer(() => This.GetOrCreateObject(key, () => CacheIndex.Create(key))).Replay().RefCount();
204+
205+
206+
var fetch = idx
203207
.Select(x => Tuple.Create(x, fetchPredicate == null || !x.Keys.Any() || fetchPredicate(x.UpdatedAt)))
204208
.Where(predicateIsTrue => predicateIsTrue.Item2)
205209
.Select(x => x.Item1)
206-
.SelectMany(index => index.Clear(This, key, absoluteExpiration))
207-
.SelectMany(index =>
208-
{
209-
var fetchObs = fetchFunc().Catch<T, Exception>(ex =>
210-
{
211-
var shouldInvalidate = shouldInvalidateOnError ?
212-
This.InvalidateObject<CacheIndex>(key) :
213-
Observable.Return(Unit.Default);
214-
return shouldInvalidate.SelectMany(__ => Observable.Throw<T>(ex));
215-
});
216-
217-
return fetchObs
218-
.SelectMany(x => x.Save<T>(This, key, absoluteExpiration))
219-
.Do(x => index.AddAndSave(This, key, x, absoluteExpiration))
220-
.Finally(() =>
210+
.Select(index => index.Clear())
211+
.SelectMany(index => fetchFunc()
212+
.Catch<T, Exception>(ex =>
221213
{
222-
This.GetObjects<T>(index.OldKeys.Except(index.Keys))
223-
.Do(dict => This.InvalidateObjects<T>(dict.Keys))
224-
.SelectMany(dict => dict.Values)
225-
.Do(removedItemsCallback)
226-
.Subscribe();
227-
});
228-
}));
229-
230-
var cache = Observable.Defer(() => This.GetOrCreateObject(key, () => CacheIndex.Create(key))
231-
.SelectMany(index => This.GetObjects<T>(index.Keys))
232-
.SelectMany(dict => dict.Values));
233-
234-
return cache.Merge(fetch).Replay().RefCount();
214+
var shouldInvalidate = shouldInvalidateOnError ?
215+
This.InvalidateObject<CacheIndex>(key) :
216+
Observable.Return(Unit.Default);
217+
return shouldInvalidate.SelectMany(__ => Observable.Throw<T>(ex));
218+
})
219+
.SelectMany(x => x.Save<T>(This, key, absoluteExpiration))
220+
.Do(x => index.Add(key, x))
221+
);
222+
223+
var cache = idx
224+
.SelectMany(index => This.GetObjects<T>(index.Keys.ToList()))
225+
.SelectMany(dict => dict.Values);
226+
227+
return cache.Merge(fetch)
228+
.Finally(async () =>
229+
{
230+
var index = await idx;
231+
await index.Save(This);
232+
233+
var list = index.OldKeys.Except(index.Keys);
234+
if (!list.Any())
235+
return;
236+
var removed = await This.GetObjects<T>(list);
237+
foreach (var d in removed.Values)
238+
removedItemsCallback(d);
239+
await This.InvalidateObjects<T>(list);
240+
})
241+
.Replay().RefCount();
235242
}
236243

237244
static bool IsExpired(IBlobCache blobCache, DateTimeOffset itemCreatedAt, TimeSpan cacheDuration)

src/GitHub.App/Extensions/ValidationExtensions.cs

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

src/GitHub.App/Factories/HostCacheFactory.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,8 @@ public IBlobCache Create(HostAddress hostAddress)
4040
IOperatingSystem OperatingSystem { get { return operatingSystem.Value; } }
4141
IBlobCacheFactory BlobCacheFactory { get { return blobCacheFactory.Value; } }
4242

43-
bool disposed;
4443
protected virtual void Dispose(bool disposing)
45-
{
46-
if (disposing)
47-
{
48-
if (disposed) return;
49-
disposed = true;
50-
if (blobCacheFactory.IsValueCreated)
51-
blobCacheFactory.Value.Dispose();
52-
}
53-
}
44+
{}
5445

5546
public void Dispose()
5647
{

src/GitHub.App/Factories/RepositoryHostFactory.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using GitHub.Models;
66
using GitHub.Primitives;
77
using GitHub.Services;
8+
using System.Reactive.Disposables;
89

910
namespace GitHub.Factories
1011
{
@@ -17,6 +18,7 @@ public class RepositoryHostFactory : IRepositoryHostFactory
1718
readonly ILoginCache loginCache;
1819
readonly IAvatarProvider avatarProvider;
1920
readonly ITwoFactorChallengeHandler twoFactorChallengeHandler;
21+
readonly CompositeDisposable hosts = new CompositeDisposable();
2022

2123
[ImportingConstructor]
2224
public RepositoryHostFactory(
@@ -38,8 +40,14 @@ public IRepositoryHost Create(HostAddress hostAddress)
3840
var apiClient = apiClientFactory.Create(hostAddress);
3941
var hostCache = hostCacheFactory.Create(hostAddress);
4042
var modelService = new ModelService(apiClient, hostCache, avatarProvider);
43+
var host = new RepositoryHost(apiClient, modelService, loginCache, twoFactorChallengeHandler);
44+
hosts.Add(host);
45+
return host;
46+
}
4147

42-
return new RepositoryHost(apiClient, modelService, loginCache, twoFactorChallengeHandler);
48+
public void Remove(IRepositoryHost host)
49+
{
50+
hosts.Remove(host);
4351
}
4452

4553
bool disposed;
@@ -48,11 +56,8 @@ protected virtual void Dispose(bool disposing)
4856
if (disposing)
4957
{
5058
if (disposed) return;
51-
52-
loginCache.Dispose();
53-
avatarProvider.Dispose();
54-
hostCacheFactory.Dispose();
5559
disposed = true;
60+
hosts.Dispose();
5661
}
5762
}
5863

0 commit comments

Comments
 (0)