From 5d91eb4f5f78ded128bd7b88b998512a39e6ec93 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Thu, 4 Sep 2025 09:38:30 -0700 Subject: [PATCH] feat: queue imported attachments for indexing --- apps/server/src/ee | 2 +- .../services/import-attachment.service.ts | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/apps/server/src/ee b/apps/server/src/ee index 38de2d0d..d658a0d6 160000 --- a/apps/server/src/ee +++ b/apps/server/src/ee @@ -1 +1 @@ -Subproject commit 38de2d0dc1ae233668cf546f3ab74046afa8986a +Subproject commit d658a0d6dc5110e11168e6a99f2db644a25af4e5 diff --git a/apps/server/src/integrations/import/services/import-attachment.service.ts b/apps/server/src/integrations/import/services/import-attachment.service.ts index 874ff892..dd73b26a 100644 --- a/apps/server/src/integrations/import/services/import-attachment.service.ts +++ b/apps/server/src/integrations/import/services/import-attachment.service.ts @@ -16,6 +16,9 @@ import { unwrapFromParagraph } from '../utils/import-formatter'; import { resolveRelativeAttachmentPath } from '../utils/import.utils'; import { load } from 'cheerio'; import pLimit from 'p-limit'; +import { InjectQueue } from '@nestjs/bullmq'; +import { Queue } from 'bullmq'; +import { QueueJob, QueueName } from '../../queue/constants'; interface AttachmentInfo { href: string; @@ -39,6 +42,7 @@ export class ImportAttachmentService { constructor( private readonly storageService: StorageService, @InjectKysely() private readonly db: KyselyDB, + @InjectQueue(QueueName.ATTACHMENT_QUEUE) private attachmentQueue: Queue, ) {} async processAttachments(opts: { @@ -579,7 +583,7 @@ export class ImportAttachmentService { if (!nonDrawioExtensions.has(ext)) { drawioFiles.push(attachment); } else { - //Skipped non-Draw.io file with mxfile MIME.}`, + //Skipped non-Draw.io file with mxfile MIME. } } @@ -792,6 +796,36 @@ export class ImportAttachmentService { }) .execute(); + // Queue PDF and DOCX files for indexing + const supportedExtensions = ['.pdf', '.docx']; + if (supportedExtensions.includes(ext.toLowerCase())) { + try { + await this.attachmentQueue.add( + QueueJob.ATTACHMENT_INDEX_CONTENT, + { attachmentId }, + { + attempts: 2, + backoff: { + type: 'exponential', + delay: 30 * 1000, + }, + deduplication: { + id: attachmentId, + }, + removeOnComplete: true, + removeOnFail: false, + }, + ); + this.logger.debug( + `Queued ${fileNameWithExt} for indexing (attachment ID: ${attachmentId})`, + ); + } catch (err) { + this.logger.error( + `Failed to queue indexing for imported attachment ${attachmentId}: ${err}`, + ); + } + } + uploadStats.completed++; if (uploadStats.completed % 10 === 0) {