Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit fdd650f

Browse files
committed
Make reeeeeally sure the views get updated data
1 parent 7297d5f commit fdd650f

File tree

8 files changed

+77
-21
lines changed

8 files changed

+77
-21
lines changed

src/GitHub.Api/Cache/CacheInterfaces.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace GitHub.Unity
55
{
66
public enum CacheType
77
{
8+
None,
89
RepositoryInfo,
910
Branches,
1011
GitLog,

src/GitHub.Api/Git/Repository.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ public bool Equals(IRepository other)
154154

155155
private void RefreshCache(CacheType cacheType)
156156
{
157-
var cache = cacheContainer.GetCache(cacheType);
158-
// if the cache has valid data, we need to force an invalidation to refresh it
159-
// if it doesn't have valid data, it will trigger an invalidation automatically
160-
if (cache.ValidateData())
161-
cache.InvalidateData();
157+
taskManager.RunInUI(() =>
158+
{
159+
var cache = cacheContainer.GetCache(cacheType);
160+
// if the cache has valid data, we need to force an invalidation to refresh it
161+
// if it doesn't have valid data, it will trigger an invalidation automatically
162+
if (cache.ValidateData())
163+
cache.InvalidateData();
164+
});
162165
}
163166

164167
private void CacheHasBeenInvalidated(CacheType cacheType)

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override void OnEnable()
7777
}
7878

7979
AttachHandlers(Repository);
80-
Repository.CheckAndRaiseEventsIfCacheNewer(lastLocalAndRemoteBranchListChangedEvent);
80+
ValidateCachedData(Repository);
8181
}
8282

8383
public override void OnDisable()
@@ -150,6 +150,13 @@ private void DetachHandlers(IRepository repository)
150150
repository.LocalAndRemoteBranchListChanged -= RepositoryOnLocalAndRemoteBranchListChanged;
151151
}
152152

153+
private void ValidateCachedData(IRepository repository)
154+
{
155+
if (lastLocalAndRemoteBranchListChangedEvent.cacheType == CacheType.None)
156+
lastLocalAndRemoteBranchListChangedEvent = new CacheUpdateEvent(CacheType.Branches, DateTimeOffset.MinValue);
157+
repository.CheckAndRaiseEventsIfCacheNewer(lastLocalAndRemoteBranchListChangedEvent);
158+
}
159+
153160
private void Render()
154161
{
155162
listID = GUIUtility.GetControlID(FocusType.Keyboard);

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ public override void OnEnable()
5252
}
5353

5454
AttachHandlers(Repository);
55-
Repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentBranchChangedEvent);
56-
Repository.CheckAndRaiseEventsIfCacheNewer(lastStatusEntriesChangedEvent);
57-
Repository.CheckAndRaiseEventsIfCacheNewer(lastLocksChangedEvent);
55+
ValidateCachedData(Repository);
5856
}
5957

6058
public override void OnDisable()
@@ -241,6 +239,20 @@ private void DetachHandlers(IRepository repository)
241239
repository.LocksChanged -= RepositoryOnLocksChanged;
242240
}
243241

242+
private void ValidateCachedData(IRepository repository)
243+
{
244+
if (lastCurrentBranchChangedEvent.cacheType == CacheType.None)
245+
lastCurrentBranchChangedEvent = new CacheUpdateEvent(CacheType.RepositoryInfo, DateTimeOffset.MinValue);
246+
if (lastStatusEntriesChangedEvent.cacheType == CacheType.None)
247+
lastStatusEntriesChangedEvent = new CacheUpdateEvent(CacheType.GitStatus, DateTimeOffset.MinValue);
248+
if (lastLocksChangedEvent.cacheType == CacheType.None)
249+
lastLocksChangedEvent = new CacheUpdateEvent(CacheType.GitLocks, DateTimeOffset.MinValue);
250+
251+
repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentBranchChangedEvent);
252+
repository.CheckAndRaiseEventsIfCacheNewer(lastStatusEntriesChangedEvent);
253+
repository.CheckAndRaiseEventsIfCacheNewer(lastLocksChangedEvent);
254+
}
255+
244256
private void MaybeUpdateData()
245257
{
246258
if (currentBranchHasUpdate)

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,7 @@ public override void OnEnable()
359359
}
360360

361361
AttachHandlers(Repository);
362-
363-
if (Repository != null)
364-
{
365-
Repository.CheckAndRaiseEventsIfCacheNewer(lastLogChangedEvent);
366-
Repository.CheckAndRaiseEventsIfCacheNewer(lastAheadBehindChangedEvent);
367-
Repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentRemoteChangedEvent);
368-
}
362+
ValidateCachedData(Repository);
369363
}
370364

371365
public override void OnDisable()
@@ -606,6 +600,19 @@ private void DetachHandlers(IRepository repository)
606600
repository.CurrentRemoteChanged -= RepositoryOnCurrentRemoteChanged;
607601
}
608602

603+
private void ValidateCachedData(IRepository repository)
604+
{
605+
if (lastLogChangedEvent.cacheType == CacheType.None)
606+
lastLogChangedEvent = new CacheUpdateEvent(CacheType.GitLog, DateTimeOffset.MinValue);
607+
if (lastAheadBehindChangedEvent.cacheType == CacheType.None)
608+
lastAheadBehindChangedEvent = new CacheUpdateEvent(CacheType.GitAheadBehind, DateTimeOffset.MinValue);
609+
if (lastCurrentRemoteChangedEvent.cacheType == CacheType.None)
610+
lastCurrentRemoteChangedEvent = new CacheUpdateEvent(CacheType.RepositoryInfo, DateTimeOffset.MinValue);
611+
repository.CheckAndRaiseEventsIfCacheNewer(lastLogChangedEvent);
612+
repository.CheckAndRaiseEventsIfCacheNewer(lastAheadBehindChangedEvent);
613+
repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentRemoteChangedEvent);
614+
}
615+
609616
private void MaybeUpdateData()
610617
{
611618
if (Repository == null)

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ProjectWindowInterface.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ public static void Initialize(IRepository repo)
3737
repository.TrackingStatusChanged += RepositoryOnStatusChanged;
3838
repository.LocksChanged += RepositoryOnLocksChanged;
3939

40-
repository.CheckAndRaiseEventsIfCacheNewer(lastRepositoryStatusChangedEvent);
41-
repository.CheckAndRaiseEventsIfCacheNewer(lastLocksChangedEvent);
4240
}
4341
}
4442

43+
private static void ValidateCachedData(IRepository repository)
44+
{
45+
if (lastRepositoryStatusChangedEvent.cacheType == CacheType.None)
46+
lastRepositoryStatusChangedEvent = new CacheUpdateEvent(CacheType.GitStatus, DateTimeOffset.MinValue);
47+
if (lastLocksChangedEvent.cacheType == CacheType.None)
48+
lastLocksChangedEvent = new CacheUpdateEvent(CacheType.GitLocks, DateTimeOffset.MinValue);
49+
repository.CheckAndRaiseEventsIfCacheNewer(lastRepositoryStatusChangedEvent);
50+
repository.CheckAndRaiseEventsIfCacheNewer(lastLocksChangedEvent);
51+
}
52+
4553
private static void RepositoryOnStatusChanged(CacheUpdateEvent cacheUpdateEvent)
4654
{
4755
if (!lastRepositoryStatusChangedEvent.Equals(cacheUpdateEvent))

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public override void OnEnable()
5858

5959
if (Repository != null)
6060
{
61-
Repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentRemoteChangedEvent);
62-
Repository.CheckAndRaiseEventsIfCacheNewer(lastLocksChangedEvent);
61+
ValidateCachedData(Repository);
6362
}
6463

6564
metricsHasChanged = true;
6665
}
6766

67+
6868
public override void OnDisable()
6969
{
7070
base.OnDisable();
@@ -156,6 +156,17 @@ private void DetachHandlers(IRepository repository)
156156
}
157157
}
158158

159+
private void ValidateCachedData(IRepository repository)
160+
{
161+
if (lastCurrentRemoteChangedEvent.cacheType == CacheType.None)
162+
lastCurrentRemoteChangedEvent = new CacheUpdateEvent(CacheType.RepositoryInfo, DateTimeOffset.MinValue);
163+
if (lastLocksChangedEvent.cacheType == CacheType.None)
164+
lastLocksChangedEvent = new CacheUpdateEvent(CacheType.GitLocks, DateTimeOffset.MinValue);
165+
166+
repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentRemoteChangedEvent);
167+
repository.CheckAndRaiseEventsIfCacheNewer(lastLocksChangedEvent);
168+
}
169+
159170
private void MaybeUpdateData()
160171
{
161172
if (metricsHasChanged)

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public override void OnEnable()
116116
Selection.activeObject = this;
117117
#endif
118118
if (Repository != null)
119-
Repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentBranchAndRemoteChangedEvent);
119+
ValidateCachedData(Repository);
120120

121121
if (ActiveView != null)
122122
ActiveView.OnEnable();
@@ -259,6 +259,13 @@ public override void Update()
259259
}
260260
}
261261

262+
private void ValidateCachedData(IRepository repository)
263+
{
264+
if (lastCurrentBranchAndRemoteChangedEvent.cacheType == CacheType.None)
265+
lastCurrentBranchAndRemoteChangedEvent = new CacheUpdateEvent(CacheType.RepositoryInfo, DateTimeOffset.MinValue);
266+
repository.CheckAndRaiseEventsIfCacheNewer(lastCurrentBranchAndRemoteChangedEvent);
267+
}
268+
262269
private void MaybeUpdateData()
263270
{
264271
if (progress != null)

0 commit comments

Comments
 (0)