mirror of
https://github.com/outline/outline.git
synced 2026-11-21 13:34:02 +03:00
* Add column and task to calculate size * Store in MB, rather than Bytes * Add cron task to recalculate attachment sizes * findAllInBatches * Index createdAt * fix: Index on incorrect table
32 lines
693 B
TypeScript
32 lines
693 B
TypeScript
import { Attachment, Team } from "@server/models";
|
|
import BaseTask, { TaskPriority } from "./BaseTask";
|
|
|
|
type Props = {
|
|
/** The teamId to operate on */
|
|
teamId: string;
|
|
};
|
|
|
|
/**
|
|
* A task that updates the team stats.
|
|
*/
|
|
export default class UpdateTeamAttachmentsSizeTask extends BaseTask<Props> {
|
|
public async perform({ teamId }: Props) {
|
|
const sizeInBytes = await Attachment.getTotalSizeForTeam(teamId);
|
|
if (!sizeInBytes) {
|
|
return;
|
|
}
|
|
|
|
await Team.update(
|
|
{ approximateTotalAttachmentsSize: sizeInBytes },
|
|
{ where: { id: teamId } }
|
|
);
|
|
}
|
|
|
|
public get options() {
|
|
return {
|
|
attempts: 1,
|
|
priority: TaskPriority.Background,
|
|
};
|
|
}
|
|
}
|