import Inject from "@entity-access/entity-access/dist/di/di.js"; import TimeSpan from "@entity-access/entity-access/dist/types/TimeSpan.js"; import Workflow, { UniqueActivity } from "@entity-access/entity-access/dist/workflows/Workflow.js"; import SocialMailContext from "../../../model/SocialMailContext.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; export default class UpdateUserStorage extends Workflow { static taskGroup = "batch"; async run() { this.failedPreserveTime = this.preserveTime = TimeSpan.fromSeconds(1); await this.updateStorage(0); await this.delay(TimeSpan.fromHours(8)); await this.updateStorage(1); } @UniqueActivity async updateStorage( n: number, @Inject db?: SocialMailContext ) { const pid = { id: this.input}; db.raiseEvents = false; db.verifyFilters = false; await db.users .where(pid, (x, p) => x.userID === p.id) .update((x) => ({ storage: Sql.coll.sum( x.userMailboxes.map((m) => m.mailbox.storage)) + Sql.coll.sum( x.fileAccessList .filter((f) => f.file.isFolder === true && f.file.parentID === null) .map((f) => f.file.fileSize)) })); } }