Fix milestone publisher and social previews
This commit is contained in:
@@ -42,7 +42,13 @@ export async function GET(request: NextRequest) {
|
||||
if (dryRun) return NextResponse.json({ milestone: { id: milestone.id, text: milestone.consentText, shareUrl }, dryRun: true });
|
||||
|
||||
const claimed = await db.$transaction(async (tx) => {
|
||||
await tx.$queryRawUnsafe('SELECT pg_advisory_xact_lock(920241)');
|
||||
// The blocking advisory-lock function returns PostgreSQL `void`, which
|
||||
// Prisma cannot deserialize. The try variant returns a real boolean and
|
||||
// keeps the lock scoped to this transaction.
|
||||
const [lock] = await tx.$queryRaw<Array<{ acquired: boolean }>>`
|
||||
SELECT pg_try_advisory_xact_lock(920241) AS acquired
|
||||
`;
|
||||
if (!lock?.acquired) return 0;
|
||||
const result = await tx.socialMilestone.updateMany({
|
||||
where: { id: milestone.id, brandStatus: 'approved' }, data: { brandStatus: 'processing', claimedAt: new Date() },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user