Conversation
…6-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…6-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
6672005 to
badb277
Compare
…6-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…6-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…ps://github.com/BinaryStudioAcademy/bsa-2026-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…6-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…6-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…6-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…ps://github.com/BinaryStudioAcademy/bsa-2026-transcripta into feat/TSA-281-queue-pages-ingest-still-splitting
…le still ingesting
@yurii-tymoshevskyi Done. Thanks for the suggestion. |
| await DocumentModel.transaction(async (trx) => { | ||
| const newlyQueuedPages = await refillPageWindow({ | ||
| documentId, | ||
| pageRepository: this.pageRepository, | ||
| quantity: PAGES_TO_QUEUE, | ||
| trx, | ||
| }); | ||
|
|
There was a problem hiding this comment.
its a condition race with worker
pageTranscribeQueue.add is called inside the transaction, so the job can be picked up before the QUEUED status is committed.
The worker then sees the page as PENDING, the claim updates 0 rows, the job is skipped, and the page stays QUEUED forever.
fix:
const newlyQueuedPages = await DocumentModel.transaction(
async (trx) =>
await refillPageWindow({
documentId,
pageRepository: this.pageRepository,
quantity: PAGES_TO_QUEUE,
trx,
}),
);
await Promise.all(
newlyQueuedPages.map((queuedPage) => {
const { id, pageNo } = queuedPage.toObject();
return this.pageTranscribeQueue.add({
documentId,
pageId: id,
pageNo,
});
}),
);
| if ( | ||
| !currentDocument || | ||
| currentDocument.status === DocumentStatus.BUDGET_STOP || | ||
| currentDocument.status === DocumentStatus.PAUSED | ||
| ) { | ||
| break; | ||
| } |
There was a problem hiding this comment.
BUDGET_STOP can be set mid-ingest.
This break exits the whole loop, so the remaining pages are never created, but finalizeIngest still saves the full pageCount.
After raising the budget and resuming, the document would be missing pages.
|
pls resolve this as first |


Closes #281
Summary
Implemented incremental page queueing during document ingestion to allow earlier processing and transcription of pages while the document ingestion is taking place. The goal of this change is to enable users to access the document's first transcription once ingestion has started, instead of waiting for the entire action to finish.
During the ingestion process, users can already begin confirming page transcriptions using a sliding window of 5 pages. As correct transcriptions are confirmed, the next pending pages are queued, ensuring a maximum of 5 pages in flight while the rest remain in a PENDING state.
Blank pages continue to be skipped, and when the ingestion process is paused or stopped, new pages stop being queued.
With this, the first page of a 30-page document will have its transcription within the first 5 seconds (in my case), compared to the 46 seconds it takes on the main branch.
Changes
BE:
preparePagesloop usingrefillPageWindowinstead of waiting until the entire document ingestion finishes.BUDGET_STOPorPAUSEDstatus mid-ingest (esto a pesar de que durante una ingestión no se puede pausar).