Add force-token cache bust for worker PDF op keys
This commit is contained in:
parent
3aad8a51e4
commit
10748c7fcd
5 changed files with 36 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { randomUUID } from 'node:crypto';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { and, eq, inArray } from 'drizzle-orm';
|
||||
import { db } from '@/db';
|
||||
|
|
@ -204,6 +205,7 @@ export async function POST(req: NextRequest, ctx: { params: Promise<{ id: string
|
|||
documentId: id,
|
||||
userId: row.userId,
|
||||
namespace: testNamespace,
|
||||
forceToken: randomUUID(),
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ export interface PdfLayoutInput {
|
|||
namespace?: string | null;
|
||||
documentObjectKey?: string;
|
||||
pdfBytes?: ArrayBuffer;
|
||||
forceToken?: string;
|
||||
onProgress?: (progress: PdfLayoutProgress) => void | Promise<void>;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,13 +166,14 @@ function buildWhisperOpKey(input: WhisperAlignInput): string {
|
|||
].join('|');
|
||||
}
|
||||
|
||||
function buildPdfOpKey(input: PdfLayoutInput): string {
|
||||
export function buildPdfOpKey(input: PdfLayoutInput): string {
|
||||
return [
|
||||
'pdf_layout',
|
||||
'v1',
|
||||
input.documentId,
|
||||
input.namespace ?? '',
|
||||
input.documentObjectKey ?? '',
|
||||
input.forceToken?.trim() || '',
|
||||
].join('|');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ interface ParsePdfJobInput {
|
|||
documentId: string;
|
||||
userId: string;
|
||||
namespace: string | null;
|
||||
forceToken?: string;
|
||||
}
|
||||
|
||||
const running = new Set<string>();
|
||||
|
|
@ -59,6 +60,7 @@ export async function parsePdfJob(input: ParsePdfJobInput): Promise<void> {
|
|||
documentId: input.documentId,
|
||||
namespace: input.namespace,
|
||||
documentObjectKey: documentKey(input.documentId, input.namespace),
|
||||
forceToken: input.forceToken,
|
||||
onProgress: writeProgress,
|
||||
});
|
||||
|
||||
|
|
|
|||
29
tests/unit/compute-worker-op-key.spec.ts
Normal file
29
tests/unit/compute-worker-op-key.spec.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import { buildPdfOpKey } from '../../src/lib/server/compute/worker';
|
||||
|
||||
test.describe('compute worker pdf opKey', () => {
|
||||
test('keeps stable key when no force token is provided', () => {
|
||||
const base = {
|
||||
documentId: 'doc-123',
|
||||
namespace: 'ns-1',
|
||||
documentObjectKey: 'docs/ns-1/doc-123',
|
||||
};
|
||||
expect(buildPdfOpKey(base)).toBe('pdf_layout|v1|doc-123|ns-1|docs/ns-1/doc-123|');
|
||||
expect(buildPdfOpKey(base)).toBe(buildPdfOpKey(base));
|
||||
});
|
||||
|
||||
test('cache-busts key when force token is provided', () => {
|
||||
const base = {
|
||||
documentId: 'doc-123',
|
||||
namespace: 'ns-1',
|
||||
documentObjectKey: 'docs/ns-1/doc-123',
|
||||
};
|
||||
const opKeyA = buildPdfOpKey({ ...base, forceToken: 'force-a' });
|
||||
const opKeyB = buildPdfOpKey({ ...base, forceToken: 'force-b' });
|
||||
const normal = buildPdfOpKey(base);
|
||||
|
||||
expect(opKeyA).not.toBe(opKeyB);
|
||||
expect(opKeyA).not.toBe(normal);
|
||||
expect(opKeyB).not.toBe(normal);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue