Skip to content

Commit 07956c2

Browse files
authored
Skip Send/Receive steps if no pending changes (#1627)
Incoming changes are detected by using PendingCommitCount; if it's 0 then there are no Mercurial changes sitting in Lexbox, so a Send/Receive would do nothing and we can save some time by skipping it. Outgoing changes are detected by looking at the FwdataChanges result from the CRDT sync code. If that is 0 then the Send/Receive would not push any new commits so we can safely skip it and save more time.
1 parent e904ed1 commit 07956c2

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

backend/FwHeadless/Services/SyncHostedService.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,15 @@ public async Task<SyncJobResult> ExecuteSync(CancellationToken stoppingToken)
161161
result.FwdataChanges);
162162

163163
await crdtSyncService.SyncHarmonyProject();
164-
var srResult2 = await srService.SendReceive(fwDataProject, projectCode);
165-
logger.LogInformation("Send/Receive result after CRDT sync: {srResult2}", srResult2.Output);
164+
if (result.FwdataChanges == 0)
165+
{
166+
logger.LogInformation("No Send/Receive needed after CRDT sync as no FW changes were made by the sync");
167+
}
168+
else
169+
{
170+
var srResult2 = await srService.SendReceive(fwDataProject, projectCode);
171+
logger.LogInformation("Send/Receive result after CRDT sync: {srResult2}", srResult2.Output);
172+
}
166173
activity?.SetStatus(ActivityStatusCode.Ok, "Sync finished");
167174
return new SyncJobResult(SyncJobResultEnum.Success, null, result);
168175
}
@@ -175,8 +182,16 @@ static async Task<FwDataMiniLcmApi> SetupFwData(FwDataProject fwDataProject,
175182
{
176183
if (File.Exists(fwDataProject.FilePath))
177184
{
178-
var srResult = await srService.SendReceive(fwDataProject, projectCode);
179-
logger.LogInformation("Send/Receive result: {srResult}", srResult.Output);
185+
var pendingHgCommits = await srService.PendingCommitCount(fwDataProject, projectCode);
186+
if (pendingHgCommits == 0)
187+
{
188+
logger.LogInformation("No Send/Receive needed before CRDT sync as there are no pending commits");
189+
}
190+
else
191+
{
192+
var srResult = await srService.SendReceive(fwDataProject, projectCode);
193+
logger.LogInformation("Send/Receive result before CRDT sync: {srResult}", srResult.Output);
194+
}
180195
}
181196
else
182197
{

0 commit comments

Comments
 (0)