Skip to content

Commit 5d2691d

Browse files
committed
Add PostgreSQL support of DequeueWithServerSideQueryAsync.
1 parent afda893 commit 5d2691d

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

src/DataAccess/QueryCacheBase.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,28 @@ FROM [PolygonJudgings] AS [p]
178178
}
179179
else if (context.Database.ProviderName == "Npgsql.EntityFrameworkCore.PostgreSQL")
180180
{
181-
/*
182-
UPDATE server_info
183-
SET status = 'active'
184-
WHERE server_ip = (
185-
SELECT server_ip
186-
FROM server_info
187-
WHERE status = 'standby'
188-
LIMIT 1
189-
FOR UPDATE SKIP LOCKED
190-
)
191-
RETURNING server_ip;
192-
*/
181+
DateTimeOffset now = DateTimeOffset.Now;
182+
FormattableString sql =
183+
$@"UPDATE ""PolygonJudgings"" AS p
184+
SET ""Server"" = {judgehostName}, ""StartTime"" = {now}, ""Status"" = {(int)Verdict.Running}
185+
WHERE p.""JudgingId"" = (
186+
SELECT p.""JudgingId""
187+
FROM ""PolygonJudgings"" AS p
188+
INNER JOIN ""PolygonSubmissions"" AS p0 ON p.""SubmissionId"" = p0.""SubmissionId""
189+
INNER JOIN ""PolygonLanguages"" AS p1 ON p0.""Language"" = p1.""LangId""
190+
INNER JOIN ""PolygonProblems"" AS p2 ON p0.""ProblemId"" = p2.""ProblemId""
191+
WHERE (((p.""Status"" = 8) AND p1.""AllowJudge"") AND p2.""AllowJudge"") AND NOT (p0.""Ignored"")
192+
ORDER BY p.""JudgingId""
193+
LIMIT 1
194+
FOR UPDATE SKIP LOCKED
195+
)
196+
RETURNING ""JudgingId""";
193197

194-
throw new NotImplementedException();
198+
var results = await context.Set<SingleEntry>()
199+
.FromSqlInterpolated(sql)
200+
.ToListAsync();
201+
202+
return results.SingleOrDefault()?.Id;
195203
}
196204
else
197205
{

0 commit comments

Comments
 (0)