mirror of
https://github.com/outline/outline.git
synced 2026-03-10 06:39:19 -05:00
@@ -44,7 +44,7 @@ async function teamPermanentDeleter(team: Team) {
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
limit: 100,
|
||||
batchLimit: 100,
|
||||
},
|
||||
async (attachments, options) => {
|
||||
await sequelize.transaction(async (transaction) => {
|
||||
@@ -72,7 +72,7 @@ async function teamPermanentDeleter(team: Team) {
|
||||
where: {
|
||||
teamId,
|
||||
},
|
||||
limit: 100,
|
||||
batchLimit: 100,
|
||||
},
|
||||
async (users) => {
|
||||
await sequelize.transaction(async (transaction) => {
|
||||
|
||||
@@ -5,6 +5,7 @@ import isObject from "lodash/isObject";
|
||||
import pick from "lodash/pick";
|
||||
import { FindOptions, NonAttribute } from "sequelize";
|
||||
import { Model as SequelizeModel } from "sequelize-typescript";
|
||||
import { Replace } from "@server/types";
|
||||
|
||||
class Model<
|
||||
TModelAttributes extends {} = any,
|
||||
@@ -17,14 +18,14 @@ class Model<
|
||||
* @param callback The function to call for each batch of results
|
||||
*/
|
||||
static async findAllInBatches<T extends Model>(
|
||||
query: FindOptions<T>,
|
||||
query: Replace<FindOptions<T>, "limit", "batchLimit">,
|
||||
callback: (results: Array<T>, query: FindOptions<T>) => Promise<void>
|
||||
) {
|
||||
if (!query.offset) {
|
||||
query.offset = 0;
|
||||
}
|
||||
if (!query.limit) {
|
||||
query.limit = 10;
|
||||
if (!query.batchLimit) {
|
||||
query.batchLimit = 10;
|
||||
}
|
||||
let results;
|
||||
|
||||
@@ -32,8 +33,8 @@ class Model<
|
||||
// @ts-expect-error this T
|
||||
results = await this.findAll<T>(query);
|
||||
await callback(results, query);
|
||||
query.offset += query.limit;
|
||||
} while (results.length >= query.limit);
|
||||
query.offset += query.batchLimit;
|
||||
} while (results.length >= query.batchLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -299,7 +299,7 @@ export default class WebsocketsProcessor {
|
||||
await GroupUser.findAllInBatches<GroupUser>(
|
||||
{
|
||||
where: { groupId: event.modelId },
|
||||
limit: 100,
|
||||
batchLimit: 100,
|
||||
},
|
||||
async (groupUsers) => {
|
||||
for (const groupUser of groupUsers) {
|
||||
@@ -478,7 +478,7 @@ export default class WebsocketsProcessor {
|
||||
where: {
|
||||
groupId: event.modelId,
|
||||
},
|
||||
limit: 100,
|
||||
batchLimit: 100,
|
||||
},
|
||||
async (groupMemberships) => {
|
||||
for (const groupMembership of groupMemberships) {
|
||||
@@ -532,7 +532,7 @@ export default class WebsocketsProcessor {
|
||||
where: {
|
||||
groupId: event.modelId,
|
||||
},
|
||||
limit: 100,
|
||||
batchLimit: 100,
|
||||
},
|
||||
async (groupMemberships) => {
|
||||
for (const groupMembership of groupMemberships) {
|
||||
@@ -591,7 +591,7 @@ export default class WebsocketsProcessor {
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
limit: 100,
|
||||
batchLimit: 100,
|
||||
},
|
||||
async (groupUsers) => {
|
||||
for (const groupMembership of groupMemberships) {
|
||||
|
||||
@@ -540,3 +540,7 @@ export type UnfurlSignature = (
|
||||
) => Promise<Unfurl | void>;
|
||||
|
||||
export type UninstallSignature = (integration: Integration) => Promise<void>;
|
||||
|
||||
export type Replace<T, K extends keyof T, N extends string> = {
|
||||
[P in keyof T as P extends K ? N : P]: T[P extends K ? K : P];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user