This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/commands/collectionExporter.js
Tom Moor 476b5e03f9
perf: Move exports to worker service (#2514)
* first pass

* fixes

* fix: Move export related emails to queue

* i18n
2021-08-31 17:41:57 -07:00

45 lines
987 B
JavaScript

// @flow
import { Collection, Event, Team, User, FileOperation } from "../models";
import { getAWSKeyForFileOp } from "../utils/s3";
export default async function collectionExporter({
collection,
team,
user,
ip,
}: {
collection?: Collection,
team: Team,
user: User,
ip: string,
}) {
const collectionId = collection?.id;
const key = getAWSKeyForFileOp(user.teamId, collection?.name || team.name);
const fileOperation = await FileOperation.create({
type: "export",
state: "creating",
key,
url: null,
size: 0,
collectionId,
userId: user.id,
teamId: user.teamId,
});
// Event is consumed on worker in queues/processors/exports
await Event.create({
name: collection ? "collections.export" : "collections.export_all",
collectionId,
teamId: user.teamId,
actorId: user.id,
modelId: fileOperation.id,
ip,
});
fileOperation.user = user;
fileOperation.collection = collection;
return fileOperation;
}