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

Commit 4c2bbc7

Browse files
Merge pull request #502 from github-for-unity/fixes/split-status-cache
Splitting git status cache
2 parents 1840178 + 402d111 commit 4c2bbc7

File tree

8 files changed

+146
-54
lines changed

8 files changed

+146
-54
lines changed

src/GitHub.Api/Cache/CacheInterfaces.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ public enum CacheType
88
RepositoryInfoCache,
99
BranchCache,
1010
GitLogCache,
11-
GitStatusCache,
11+
GitTrackingStatusCache,
12+
GitStatusEntriesCache,
1213
GitLocksCache,
1314
GitUserCache
1415
}
@@ -20,7 +21,8 @@ public interface ICacheContainer
2021

2122
IBranchCache BranchCache { get; }
2223
IGitLogCache GitLogCache { get; }
23-
IGitStatusCache GitStatusCache { get; }
24+
IGitTrackingStatusCache GitTrackingStatusCache { get; }
25+
IGitStatusEntriesCache GitStatusEntriesCache { get; }
2426
IGitLocksCache GitLocksCache { get; }
2527
IGitUserCache GitUserCache { get; }
2628
IRepositoryInfoCache RepositoryInfoCache { get; }
@@ -53,10 +55,14 @@ public interface IGitUserCache : IManagedCache
5355
string Email { get; set; }
5456
}
5557

56-
public interface IGitStatusCache : IManagedCache
58+
public interface IGitTrackingStatusCache : IManagedCache
5759
{
5860
int Ahead { get; set; }
5961
int Behind { get; set; }
62+
}
63+
64+
public interface IGitStatusEntriesCache : IManagedCache
65+
{
6066
List<GitStatusEntry> Entries { get; set; }
6167
}
6268

src/GitHub.Api/Git/IRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public interface IRepository : IEquatable<IRepository>
2121

2222
void CheckLogChangedEvent(CacheUpdateEvent gitLogCacheUpdateEvent);
2323
void CheckStatusChangedEvent(CacheUpdateEvent cacheUpdateEvent);
24+
void CheckStatusEntriesChangedEvent(CacheUpdateEvent cacheUpdateEvent);
2425
void CheckCurrentBranchChangedEvent(CacheUpdateEvent cacheUpdateEvent);
2526
void CheckCurrentRemoteChangedEvent(CacheUpdateEvent cacheUpdateEvent);
2627
void CheckCurrentBranchAndRemoteChangedEvent(CacheUpdateEvent cacheUpdateEvent);
@@ -68,7 +69,8 @@ public interface IRepository : IEquatable<IRepository>
6869
List<GitLogEntry> CurrentLog { get; }
6970

7071
event Action<CacheUpdateEvent> LogChanged;
71-
event Action<CacheUpdateEvent> StatusChanged;
72+
event Action<CacheUpdateEvent> TrackingStatusChanged;
73+
event Action<CacheUpdateEvent> StatusEntriesChanged;
7274
event Action<CacheUpdateEvent> CurrentBranchChanged;
7375
event Action<CacheUpdateEvent> CurrentRemoteChanged;
7476
event Action<CacheUpdateEvent> CurrentBranchAndRemoteChanged;

src/GitHub.Api/Git/Repository.cs

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class Repository : IEquatable<Repository>, IRepository
1616
private string name;
1717

1818
public event Action<CacheUpdateEvent> LogChanged;
19-
public event Action<CacheUpdateEvent> StatusChanged;
19+
public event Action<CacheUpdateEvent> TrackingStatusChanged;
20+
public event Action<CacheUpdateEvent> StatusEntriesChanged;
2021
public event Action<CacheUpdateEvent> CurrentBranchChanged;
2122
public event Action<CacheUpdateEvent> CurrentRemoteChanged;
2223
public event Action<CacheUpdateEvent> CurrentBranchAndRemoteChanged;
@@ -128,7 +129,7 @@ public void CheckLogChangedEvent(CacheUpdateEvent cacheUpdateEvent)
128129

129130
public void CheckStatusChangedEvent(CacheUpdateEvent cacheUpdateEvent)
130131
{
131-
var managedCache = cacheContainer.GitStatusCache;
132+
var managedCache = cacheContainer.GitTrackingStatusCache;
132133
var raiseEvent = managedCache.LastUpdatedAt != cacheUpdateEvent.UpdatedTime;
133134

134135
Logger.Trace("Check GitStatusCache CacheUpdateEvent Current:{0} Check:{1} Result:{2}", managedCache.LastUpdatedAt,
@@ -138,7 +139,23 @@ public void CheckStatusChangedEvent(CacheUpdateEvent cacheUpdateEvent)
138139
{
139140
var dateTimeOffset = managedCache.LastUpdatedAt;
140141
var updateEvent = new CacheUpdateEvent { UpdatedTime = dateTimeOffset };
141-
HandleGitStatusCacheUpdatedEvent(updateEvent);
142+
HandleGitTrackingStatusCacheUpdatedEvent(updateEvent);
143+
}
144+
}
145+
146+
public void CheckStatusEntriesChangedEvent(CacheUpdateEvent cacheUpdateEvent)
147+
{
148+
var managedCache = cacheContainer.GitStatusEntriesCache;
149+
var raiseEvent = managedCache.LastUpdatedAt != cacheUpdateEvent.UpdatedTime;
150+
151+
Logger.Trace("Check GitStatusEntriesCache CacheUpdateEvent Current:{0} Check:{1} Result:{2}", managedCache.LastUpdatedAt,
152+
cacheUpdateEvent.UpdatedTime, raiseEvent);
153+
154+
if (raiseEvent)
155+
{
156+
var dateTimeOffset = managedCache.LastUpdatedAt;
157+
var updateEvent = new CacheUpdateEvent { UpdatedTime = dateTimeOffset };
158+
HandleGitStatusEntriesCacheUpdatedEvent(updateEvent);
142159
}
143160
}
144161

@@ -263,8 +280,8 @@ private void CacheContainer_OnCacheInvalidated(CacheType cacheType)
263280
repositoryManager?.UpdateGitLog();
264281
break;
265282

266-
case CacheType.GitStatusCache:
267-
repositoryManager?.UpdateGitStatus();
283+
case CacheType.GitTrackingStatusCache:
284+
repositoryManager?.UpdateGitAheadBehindStatus();
268285
break;
269286

270287
case CacheType.GitLocksCache:
@@ -277,6 +294,10 @@ private void CacheContainer_OnCacheInvalidated(CacheType cacheType)
277294
case CacheType.RepositoryInfoCache:
278295
break;
279296

297+
case CacheType.GitStatusEntriesCache:
298+
repositoryManager?.UpdateGitStatus();
299+
break;
300+
280301
default:
281302
throw new ArgumentOutOfRangeException(nameof(cacheType), cacheType, null);
282303
}
@@ -295,8 +316,8 @@ private void CacheContainer_OnCacheUpdated(CacheType cacheType, DateTimeOffset o
295316
HandleGitLogCacheUpdatedEvent(cacheUpdateEvent);
296317
break;
297318

298-
case CacheType.GitStatusCache:
299-
HandleGitStatusCacheUpdatedEvent(cacheUpdateEvent);
319+
case CacheType.GitTrackingStatusCache:
320+
HandleGitTrackingStatusCacheUpdatedEvent(cacheUpdateEvent);
300321
break;
301322

302323
case CacheType.GitLocksCache:
@@ -310,6 +331,10 @@ private void CacheContainer_OnCacheUpdated(CacheType cacheType, DateTimeOffset o
310331
HandleRepositoryInfoCacheUpdatedEvent(cacheUpdateEvent);
311332
break;
312333

334+
case CacheType.GitStatusEntriesCache:
335+
HandleGitStatusEntriesCacheUpdatedEvent(cacheUpdateEvent);
336+
break;
337+
313338
default:
314339
throw new ArgumentOutOfRangeException(nameof(cacheType), cacheType, null);
315340
}
@@ -329,10 +354,16 @@ private void HandleGitLocksCacheUpdatedEvent(CacheUpdateEvent cacheUpdateEvent)
329354
LocksChanged?.Invoke(cacheUpdateEvent);
330355
}
331356

332-
private void HandleGitStatusCacheUpdatedEvent(CacheUpdateEvent cacheUpdateEvent)
357+
private void HandleGitTrackingStatusCacheUpdatedEvent(CacheUpdateEvent cacheUpdateEvent)
358+
{
359+
Logger.Trace("GitTrackingStatusCache Updated {0}", cacheUpdateEvent.UpdatedTimeString);
360+
TrackingStatusChanged?.Invoke(cacheUpdateEvent);
361+
}
362+
363+
private void HandleGitStatusEntriesCacheUpdatedEvent(CacheUpdateEvent cacheUpdateEvent)
333364
{
334-
Logger.Trace("GitStatusCache Updated {0}", cacheUpdateEvent.UpdatedTimeString);
335-
StatusChanged?.Invoke(cacheUpdateEvent);
365+
Logger.Trace("GitStatusEntriesCache Updated {0}", cacheUpdateEvent.UpdatedTimeString);
366+
StatusEntriesChanged?.Invoke(cacheUpdateEvent);
336367
}
337368

338369
private void HandleGitLogCacheUpdatedEvent(CacheUpdateEvent cacheUpdateEvent)
@@ -498,20 +529,20 @@ private ConfigRemote? CurrentConfigRemote
498529

499530
public int CurrentAhead
500531
{
501-
get { return cacheContainer.GitStatusCache.Ahead; }
502-
private set { cacheContainer.GitStatusCache.Ahead = value; }
532+
get { return cacheContainer.GitTrackingStatusCache.Ahead; }
533+
private set { cacheContainer.GitTrackingStatusCache.Ahead = value; }
503534
}
504535

505536
public int CurrentBehind
506537
{
507-
get { return cacheContainer.GitStatusCache.Behind; }
508-
private set { cacheContainer.GitStatusCache.Behind = value; }
538+
get { return cacheContainer.GitTrackingStatusCache.Behind; }
539+
private set { cacheContainer.GitTrackingStatusCache.Behind = value; }
509540
}
510541

511542
public List<GitStatusEntry> CurrentChanges
512543
{
513-
get { return cacheContainer.GitStatusCache.Entries; }
514-
private set { cacheContainer.GitStatusCache.Entries = value; }
544+
get { return cacheContainer.GitStatusEntriesCache.Entries; }
545+
private set { cacheContainer.GitStatusEntriesCache.Entries = value; }
515546
}
516547

517548
public GitBranch? CurrentBranch

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,17 +828,16 @@ public override TimeSpan DataTimeout
828828
}
829829
}
830830

831-
[Location("cache/gitstatus.yaml", LocationAttribute.Location.LibraryFolder)]
832-
sealed class GitStatusCache : ManagedCacheBase<GitStatusCache>, IGitStatusCache
831+
[Location("cache/gittrackingstatus.yaml", LocationAttribute.Location.LibraryFolder)]
832+
sealed class GitTrackingStatusCache : ManagedCacheBase<GitTrackingStatusCache>, IGitTrackingStatusCache
833833
{
834834
[SerializeField] private string lastUpdatedAtString = DateTimeOffset.MinValue.ToString(Constants.Iso8601Format);
835835
[SerializeField] private string lastVerifiedAtString = DateTimeOffset.MinValue.ToString(Constants.Iso8601Format);
836836
[SerializeField] private string initializedAtString = DateTimeOffset.MinValue.ToString(Constants.Iso8601Format);
837837
[SerializeField] private int ahead;
838838
[SerializeField] private int behind;
839-
[SerializeField] private List<GitStatusEntry> entries = new List<GitStatusEntry>();
840839

841-
public GitStatusCache() : base(true)
840+
public GitTrackingStatusCache() : base(true)
842841
{ }
843842

844843
public int Ahead
@@ -889,6 +888,41 @@ public int Behind
889888
}
890889
}
891890

891+
public override string LastUpdatedAtString
892+
{
893+
get { return lastUpdatedAtString; }
894+
protected set { lastUpdatedAtString = value; }
895+
}
896+
897+
public override string LastVerifiedAtString
898+
{
899+
get { return lastVerifiedAtString; }
900+
protected set { lastVerifiedAtString = value; }
901+
}
902+
903+
public override string InitializedAtString
904+
{
905+
get { return initializedAtString; }
906+
protected set { initializedAtString = value; }
907+
}
908+
909+
public override TimeSpan DataTimeout
910+
{
911+
get { return TimeSpan.FromMinutes(1); }
912+
}
913+
}
914+
915+
[Location("cache/gitstatusentries.yaml", LocationAttribute.Location.LibraryFolder)]
916+
sealed class GitStatusEntriesCache : ManagedCacheBase<GitStatusEntriesCache>, IGitStatusEntriesCache
917+
{
918+
[SerializeField] private string lastUpdatedAtString = DateTimeOffset.MinValue.ToString(Constants.Iso8601Format);
919+
[SerializeField] private string lastVerifiedAtString = DateTimeOffset.MinValue.ToString(Constants.Iso8601Format);
920+
[SerializeField] private string initializedAtString = DateTimeOffset.MinValue.ToString(Constants.Iso8601Format);
921+
[SerializeField] private List<GitStatusEntry> entries = new List<GitStatusEntry>();
922+
923+
public GitStatusEntriesCache() : base(true)
924+
{ }
925+
892926
public List<GitStatusEntry> Entries
893927
{
894928
get

src/UnityExtension/Assets/Editor/GitHub.Unity/CacheContainer.cs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public class CacheContainer : ICacheContainer
1414

1515
private IGitLogCache gitLogCache;
1616

17-
private IGitStatusCache gitStatusCache;
17+
private IGitTrackingStatusCache gitTrackingStatusCache;
18+
19+
private IGitStatusEntriesCache gitStatusEntriesCache;
1820

1921
private IGitUserCache gitUserCache;
2022

@@ -32,8 +34,11 @@ private IManagedCache GetManagedCache(CacheType cacheType)
3234
case CacheType.GitLogCache:
3335
return GitLogCache;
3436

35-
case CacheType.GitStatusCache:
36-
return GitStatusCache;
37+
case CacheType.GitTrackingStatusCache:
38+
return GitTrackingStatusCache;
39+
40+
case CacheType.GitStatusEntriesCache:
41+
return GitStatusEntriesCache;
3742

3843
case CacheType.GitLocksCache:
3944
return GitLocksCache;
@@ -55,7 +60,7 @@ public void ValidateAll()
5560
{
5661
BranchCache.ValidateData();
5762
GitLogCache.ValidateData();
58-
GitStatusCache.ValidateData();
63+
GitTrackingStatusCache.ValidateData();
5964
GitLocksCache.ValidateData();
6065
GitUserCache.ValidateData();
6166
}
@@ -69,7 +74,7 @@ public void InvalidateAll()
6974
{
7075
BranchCache.InvalidateData();
7176
GitLogCache.InvalidateData();
72-
GitStatusCache.InvalidateData();
77+
GitTrackingStatusCache.InvalidateData();
7378
GitLocksCache.InvalidateData();
7479
GitUserCache.InvalidateData();
7580
}
@@ -116,17 +121,31 @@ public IGitLogCache GitLogCache
116121
}
117122
}
118123

119-
public IGitStatusCache GitStatusCache
124+
public IGitTrackingStatusCache GitTrackingStatusCache
125+
{
126+
get
127+
{
128+
if (gitTrackingStatusCache == null)
129+
{
130+
gitTrackingStatusCache = Unity.GitTrackingStatusCache.Instance;
131+
gitTrackingStatusCache.CacheInvalidated += () => OnCacheInvalidated(CacheType.GitTrackingStatusCache);
132+
gitTrackingStatusCache.CacheUpdated += datetime => OnCacheUpdated(CacheType.GitTrackingStatusCache, datetime);
133+
}
134+
return gitTrackingStatusCache;
135+
}
136+
}
137+
138+
public IGitStatusEntriesCache GitStatusEntriesCache
120139
{
121140
get
122141
{
123-
if (gitStatusCache == null)
142+
if (gitStatusEntriesCache == null)
124143
{
125-
gitStatusCache = Unity.GitStatusCache.Instance;
126-
gitStatusCache.CacheInvalidated += () => OnCacheInvalidated(CacheType.GitStatusCache);
127-
gitStatusCache.CacheUpdated += datetime => OnCacheUpdated(CacheType.GitStatusCache, datetime);
144+
gitStatusEntriesCache = Unity.GitStatusEntriesCache.Instance;
145+
gitStatusEntriesCache.CacheInvalidated += () => OnCacheInvalidated(CacheType.GitStatusEntriesCache);
146+
gitStatusEntriesCache.CacheUpdated += datetime => OnCacheUpdated(CacheType.GitStatusEntriesCache, datetime);
128147
}
129-
return gitStatusCache;
148+
return gitStatusEntriesCache;
130149
}
131150
}
132151

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ChangesView : Subview
2626
[SerializeField] private string currentBranch = "[unknown]";
2727
[SerializeField] private Vector2 horizontalScroll;
2828
[SerializeField] private CacheUpdateEvent lastCurrentBranchChangedEvent;
29-
[SerializeField] private CacheUpdateEvent lastStatusChangedEvent;
29+
[SerializeField] private CacheUpdateEvent lastStatusEntriesChangedEvent;
3030
[SerializeField] private ChangesetTreeView tree = new ChangesetTreeView();
3131

3232
public override void InitializeView(IView parent)
@@ -43,7 +43,7 @@ public override void OnEnable()
4343
if (Repository != null)
4444
{
4545
Repository.CheckCurrentBranchChangedEvent(lastCurrentBranchChangedEvent);
46-
Repository.CheckStatusChangedEvent(lastStatusChangedEvent);
46+
Repository.CheckStatusEntriesChangedEvent(lastStatusEntriesChangedEvent);
4747
}
4848
}
4949

@@ -103,11 +103,11 @@ public override void OnGUI()
103103
OnCommitDetailsAreaGUI();
104104
}
105105

106-
private void RepositoryOnStatusChanged(CacheUpdateEvent cacheUpdateEvent)
106+
private void RepositoryOnStatusEntriesChanged(CacheUpdateEvent cacheUpdateEvent)
107107
{
108-
if (!lastStatusChangedEvent.Equals(cacheUpdateEvent))
108+
if (!lastStatusEntriesChangedEvent.Equals(cacheUpdateEvent))
109109
{
110-
lastStatusChangedEvent = cacheUpdateEvent;
110+
lastStatusEntriesChangedEvent = cacheUpdateEvent;
111111
currentStatusHasUpdate = true;
112112
Redraw();
113113
}
@@ -131,7 +131,7 @@ private void AttachHandlers(IRepository repository)
131131
}
132132

133133
repository.CurrentBranchChanged += RepositoryOnCurrentBranchChanged;
134-
repository.StatusChanged += RepositoryOnStatusChanged;
134+
repository.StatusEntriesChanged += RepositoryOnStatusEntriesChanged;
135135
}
136136

137137
private void DetachHandlers(IRepository repository)
@@ -142,7 +142,7 @@ private void DetachHandlers(IRepository repository)
142142
}
143143

144144
repository.CurrentBranchChanged -= RepositoryOnCurrentBranchChanged;
145-
repository.StatusChanged -= RepositoryOnStatusChanged;
145+
repository.StatusEntriesChanged -= RepositoryOnStatusEntriesChanged;
146146
}
147147

148148
private void MaybeUpdateData()

0 commit comments

Comments
 (0)