fix: a PDF's resolution is worked out at the scan, not at checkout

create_quote downloaded every PDF sheet (up to 150 MB) and parsed it inside
the customer's request, behind nginx's 30 s. The worker's scan already reads
every upload before the Site lets the customer continue, so it now stores
the PDF's DPI on the upload (uploads.pdf_checked, pdf_dpi) and the checkout
reads the number. An upload scanned before this, or whose work-out failed,
is read at checkout as before (Critical Corrections 2, step 2).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-10 10:47:08 -03:00
parent 17463c0298
commit 29b79db806
5 changed files with 65 additions and 10 deletions

View File

@@ -114,6 +114,17 @@ class GradeCheckTests(unittest.TestCase):
self.assertEqual(files.head(png_row)[:8], b'\x89PNG\r\n\x1a\n')
self.assertEqual(storage.heads, 1)
def test_a_scanned_pdf_is_not_read_again(self):
storage = CountingStorage({'k.pdf': b'%PDF-1.4 test'})
files = grade_check.Files(storage)
self.assertEqual(files.pdf_dpi({'object_key': 'k.pdf', 'size': 15, 'name': 'a.pdf',
'pdf_checked': True, 'pdf_dpi': 150}), 150)
self.assertIsNone(files.pdf_dpi({'object_key': 'unreadable.pdf', 'size': 1, 'name': 'b.pdf',
'pdf_checked': True, 'pdf_dpi': None}))
self.assertIsNone(files.pdf_dpi({'object_key': 'big.pdf', 'size': grade_check.PDF_MAX_BYTES + 1,
'name': 'big.pdf'}))
self.assertEqual(storage.downloads, 0)
def test_resolution_boundaries_and_consent(self):
width = lambda dpi: int(dpi * 57 / 2.54) + 1
files = FakeFiles({f'{dpi}.png': encoded('PNG', (width(dpi), 20))