summaryrefslogtreecommitdiff
path: root/packages/backend/src/queue/processors
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-12-10 01:22:35 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-12-10 01:22:35 +0900
commit20134a53678fa0654aa4f1a56aebbef6347f9320 (patch)
tree4d84191dfcd69b8f39c9a4af01987c7e2f8dbdd5 /packages/backend/src/queue/processors
parentrefactor(client): :sparkles: (diff)
downloadsharkey-20134a53678fa0654aa4f1a56aebbef6347f9320.tar.gz
sharkey-20134a53678fa0654aa4f1a56aebbef6347f9320.tar.bz2
sharkey-20134a53678fa0654aa4f1a56aebbef6347f9320.zip
feat: improve follow export
Diffstat (limited to 'packages/backend/src/queue/processors')
-rw-r--r--packages/backend/src/queue/processors/db/export-following.ts31
1 files changed, 16 insertions, 15 deletions
diff --git a/packages/backend/src/queue/processors/db/export-following.ts b/packages/backend/src/queue/processors/db/export-following.ts
index 54e3b11372..fbb9e25247 100644
--- a/packages/backend/src/queue/processors/db/export-following.ts
+++ b/packages/backend/src/queue/processors/db/export-following.ts
@@ -6,13 +6,14 @@ import { queueLogger } from '../../logger';
import addFile from '@/services/drive/add-file';
import * as dateFormat from 'dateformat';
import { getFullApAccount } from '@/misc/convert-host';
-import { Users, Followings } from '@/models/index';
-import { MoreThan } from 'typeorm';
+import { Users, Followings, Mutings } from '@/models/index';
+import { In, MoreThan, Not } from 'typeorm';
import { DbUserJobData } from '@/queue/types';
+import { Following } from '@/models/entities/following';
const logger = queueLogger.createSubLogger('export-following');
-export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: any): Promise<void> {
+export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: () => void): Promise<void> {
logger.info(`Exporting following of ${job.data.user.id} ...`);
const user = await Users.findOne(job.data.user.id);
@@ -22,7 +23,7 @@ export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: any):
}
// Create temp file
- const [path, cleanup] = await new Promise<[string, any]>((res, rej) => {
+ const [path, cleanup] = await new Promise<[string, () => void]>((res, rej) => {
tmp.file((e, path, fd, cleanup) => {
if (e) return rej(e);
res([path, cleanup]);
@@ -33,13 +34,17 @@ export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: any):
const stream = fs.createWriteStream(path, { flags: 'a' });
- let exportedCount = 0;
- let cursor: any = null;
+ let cursor: Following['id'] | null = null;
+
+ const mutings = job.data.excludeMuting ? await Mutings.find({
+ muterId: user.id,
+ }) : [];
while (true) {
const followings = await Followings.find({
where: {
followerId: user.id,
+ ...(mutings.length > 0 ? { followeeId: Not(In(mutings.map(x => x.muteeId))) } : {}),
...(cursor ? { id: MoreThan(cursor) } : {}),
},
take: 100,
@@ -49,7 +54,6 @@ export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: any):
});
if (followings.length === 0) {
- job.progress(100);
break;
}
@@ -58,7 +62,11 @@ export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: any):
for (const following of followings) {
const u = await Users.findOne({ id: following.followeeId });
if (u == null) {
- exportedCount++; continue;
+ continue;
+ }
+
+ if (job.data.excludeInactive && u.updatedAt && (Date.now() - u.updatedAt.getTime() > 1000 * 60 * 60 * 24 * 90)) {
+ continue;
}
const content = getFullApAccount(u.username, u.host);
@@ -72,14 +80,7 @@ export async function exportFollowing(job: Bull.Job<DbUserJobData>, done: any):
}
});
});
- exportedCount++;
}
-
- const total = await Followings.count({
- followerId: user.id,
- });
-
- job.progress(exportedCount / total);
}
stream.end();