From 48d58bb60e077882bfc496db5b2a33eecb5ccad9 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Sun, 5 Sep 2021 19:40:19 -0400 Subject: [PATCH] Fix auto updater creating conflicting RevInfos --- .../Components/Instance.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Instance.cs b/src/Tgstation.Server.Host/Components/Instance.cs index b591c8f401..6d5378dc93 100644 --- a/src/Tgstation.Server.Host/Components/Instance.cs +++ b/src/Tgstation.Server.Host/Components/Instance.cs @@ -308,19 +308,22 @@ namespace Tgstation.Server.Host.Components cancellationToken) .ConfigureAwait(false); - Task LoadRevInfo() => databaseContext.RevisionInformations - .AsQueryable() - .Where(x => x.CommitSha == startSha && x.Instance.Id == metadata.Id) - .Include(x => x.ActiveTestMerges).ThenInclude(x => x.TestMerge) - .FirstOrDefaultAsync(cancellationToken); - - RevisionInformation currentRevInfo = null; var hasDbChanges = false; + RevisionInformation currentRevInfo = null; Models.Instance attachedInstance = null; async Task UpdateRevInfo(string currentHead, bool onOrigin, IEnumerable updatedTestMerges) { if (currentRevInfo == null) - currentRevInfo = await LoadRevInfo().ConfigureAwait(false); + { + logger.LogTrace("Loading revision info for commit {0}...", startSha.Substring(0, 7)); + currentRevInfo = await databaseContext + .RevisionInformations + .AsQueryable() + .Where(x => x.CommitSha == startSha && x.Instance.Id == metadata.Id) + .Include(x => x.ActiveTestMerges) + .ThenInclude(x => x.TestMerge) + .FirstOrDefaultAsync(cancellationToken).ConfigureAwait(false); + } if (currentRevInfo == default) { @@ -328,6 +331,12 @@ namespace Tgstation.Server.Host.Components onOrigin = true; } + if (currentRevInfo.CommitSha == currentHead) + { + logger.LogTrace("Not updating rev-info, already in DB."); + return; + } + if (attachedInstance == null) { attachedInstance = new Models.Instance @@ -347,6 +356,7 @@ namespace Tgstation.Server.Host.Components : await repo.GetOriginSha(cancellationToken).ConfigureAwait(false), Instance = attachedInstance, }; + if (!onOrigin) currentRevInfo.ActiveTestMerges = new List( updatedTestMerges ?? oldRevInfo.ActiveTestMerges);