Skip to content

Commit c651e71

Browse files
committed
refactor: move rate limitation from Welcome to RepositoryNode
Signed-off-by: leo <longshuang@msn.cn>
1 parent f88f920 commit c651e71

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/ViewModels/RepositoryNode.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Text.Json.Serialization;
45
using System.Threading.Tasks;
@@ -136,7 +137,7 @@ public void Delete()
136137
activePage.Popup = new DeleteRepositoryNode(this);
137138
}
138139

139-
public async Task UpdateStatusAsync()
140+
public async Task UpdateStatusAsync(bool force)
140141
{
141142
if (!_isRepository || !Directory.Exists(_id))
142143
{
@@ -146,12 +147,20 @@ public async Task UpdateStatusAsync()
146147
if (SubNodes.Count > 0)
147148
{
148149
foreach (var subNode in SubNodes)
149-
await subNode.UpdateStatusAsync();
150+
await subNode.UpdateStatusAsync(force);
150151
}
151152

152153
return;
153154
}
154155

156+
if (!force)
157+
{
158+
var passed = DateTime.Now - _lastUpdateStatus;
159+
if (passed.TotalSeconds < 10.0)
160+
return;
161+
}
162+
163+
_lastUpdateStatus = DateTime.Now;
155164
LocalChanges = await new Commands.CountLocalChanges(_id, true) { RaiseError = false }.GetResultAsync();
156165

157166
var branches = await new Commands.QueryBranches(_id) { RaiseError = false }.GetResultAsync();
@@ -175,5 +184,6 @@ public async Task UpdateStatusAsync()
175184
private bool _isVisible = true;
176185
private Models.Branch _currentBranch = null;
177186
private int _localChanges = 0;
187+
private DateTime _lastUpdateStatus = DateTime.UnixEpoch.ToLocalTime();
178188
}
179189
}

src/ViewModels/Welcome.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,8 @@ public void Refresh()
5454

5555
public async Task UpdateStatusAsync(bool force)
5656
{
57-
if (!force)
58-
{
59-
var passed = DateTime.Now - _lastUpdateStatus;
60-
if (passed.TotalSeconds < 10.0)
61-
return;
62-
}
63-
64-
_lastUpdateStatus = DateTime.Now;
6557
foreach (var node in Preferences.Instance.RepositoryNodes)
66-
await node.UpdateStatusAsync();
58+
await node.UpdateStatusAsync(force);
6759
}
6860

6961
public void ToggleNodeIsExpanded(RepositoryNode node)
@@ -283,7 +275,6 @@ private void MakeTreeRows(List<RepositoryNode> rows, List<RepositoryNode> nodes,
283275
}
284276
}
285277

286-
private DateTime _lastUpdateStatus = DateTime.UnixEpoch.ToLocalTime();
287278
private string _searchFilter = string.Empty;
288279
}
289280
}

0 commit comments

Comments
 (0)