// import Inject from "@entity-access/entity-access/dist/di/di.js"; // import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js"; // import SocialMailContext from "../../model/SocialMailContext.js"; // import TimeSpan from "@entity-access/entity-access/dist/types/TimeSpan.js"; // import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; // import WorkflowContext from "@entity-access/entity-access/dist/workflows/WorkflowContext.js"; // import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; // import BaseStorage from "../../storage/BaseStorage.js"; // import TempFileService from "../../storage/TempFileService.js"; // import { Extract } from "../../services/extract/Extract.js"; // export default class IndexMailboxWorkflow extends Workflow { // static taskGroup = "batch"; // static startIndexing(context: WorkflowContext, id: number) { // return context.queue(IndexMailboxWorkflow, id, { // id: `index-mailbox-${id}` // }); // } // async run() { // this.preserveTime = TimeSpan.fromMinutes(1); // this.failedPreserveTime = TimeSpan.fromMinutes(5); // await this.index(); // } // @UniqueActivity // async index( // @Inject db?: SocialMailContext, // @Inject storage?: BaseStorage, // @Inject tempFileService?: TempFileService // ) { // db.raiseEvents = false; // db.verifyFilters = false; // const mailboxID = this.input; // const mailbox = await db.mailboxes // .where({ mailboxID }, (x, p) => x.mailboxID === p.mailboxID && x.indexAttachments === true) // .first(); // if (!mailbox) { // return; // } // if (!mailbox.indexAttachments) { // return; // } // const start = DateTime.now; // const mailboxQuery = db.mailboxEmails.where({ mailboxID }, (x, p) => x.mailboxID === p.mailboxID); // // start in descending order // // let us only do 10 at times.. // while(DateTime.now.diff(start).totalMinutes < 5) { // let recentQuery = mailboxQuery; // if (mailbox.recentID) { // recentQuery = recentQuery.where(mailbox, (x, p) => x.emailID > p.recentID); // } // const mailboxEmails = await recentQuery.orderBy({}, (x, p) => x.emailID) // .limit(10) // .toArray(); // const ids = mailboxEmails.map((x) => x.emailID); // if (!ids.length) { // break; // } // const files = await db.appFiles // .where({ ids }, (x, p) => // x.emailID in p.ids // && x.fileContent.searchable === null // ) // .include((x) => x.fileContent) // .toArray(); // for (const iterator of files) { // // get text... // const file = await tempFileService.downloadAppFile(iterator); // const text = await Extract.text(file, mailbox.indexImageAttachments); // iterator.fileContent.searchable = text ?? ""; // } // mailbox.recentID = ids.pop(); // await db.saveChangesWithoutEvents(); // db.changeSet.clear(); // } // } // }