Skip to content

Commit 1ad69e8

Browse files
committed
Delete test runs with raw sql
1 parent d1bfc2f commit 1ad69e8

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Services/Administration/OJS.Services.Administration.Business/Contests/ContestsImportBusinessService.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ private async Task UpdateContest(
289289
existingContest.AutoChangeTestsFeedbackVisibility = sourceContest.AutoChangeTestsFeedbackVisibility;
290290
existingContest.Duration = sourceContest.Duration;
291291

292+
if (!dryRun)
293+
{
294+
await testRunsData.ExecuteSqlCommandWithTimeout($"""
295+
DELETE tr FROM [OpenJudgeSystem].[dbo].[TestRuns] tr
296+
INNER JOIN [OpenJudgeSystem].[dbo].[Tests] t ON tr.TestId = t.Id
297+
INNER JOIN [OpenJudgeSystem].[dbo].[Problems] p ON p.Id = t.ProblemId
298+
INNER JOIN [OpenJudgeSystem].[dbo].[ProblemGroups] pg ON pg.Id = p.ProblemGroupId
299+
INNER JOIN [OpenJudgeSystem].[dbo].[Contests] c ON c.Id = pg.ContestId
300+
WHERE c.Id = {existingContest.Id}
301+
""",
302+
60);
303+
304+
result.AppendLine(CultureInfo.InvariantCulture, $"<p>Test runs for contest <b>\"{sourceContest.Name}\"</b> deleted successfully.</p>");
305+
}
306+
292307
// Process each problem in the group
293308
foreach (var sourceProblemGroup in sourceContest.ProblemGroups)
294309
{
@@ -328,16 +343,10 @@ private async Task UpdateContest(
328343
else
329344
{
330345
// Clear existing collections to update them
331-
result.AppendLine(CultureInfo.InvariantCulture, $"<p><b>----Update:</b> Problem <b>\"{sourceProblem.Name}\"</b> will be updated. Tests will be replaced. Test runs will be deleted.</p>");
346+
result.AppendLine(CultureInfo.InvariantCulture, $"<p><b>----Update:</b> Problem <b>\"{sourceProblem.Name}\"</b> will be updated. Tests will be replaced.</p>");
332347
existingProblem.Tests.Clear();
333348
existingProblem.Resources.Clear();
334349
existingProblem.SubmissionTypesInProblems.Clear();
335-
336-
if (!dryRun)
337-
{
338-
// Delete test runs for the problem, as they are no longer valid after importing new tests
339-
await testRunsData.DeleteByProblem(existingProblem.Id);
340-
}
341350
}
342351

343352
// Update problem properties

0 commit comments

Comments
 (0)