diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-04-14 20:38:55 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-04-14 20:38:55 +0900 |
| commit | d66e4b7ff97d512e2a2523815e2eef170456b37f (patch) | |
| tree | 59ae1a102d88b5c2c2236b734ea4a584b4f9ba46 /src/queue/processors/db/export-mute.ts | |
| parent | 10.100.0 (diff) | |
| parent | 11.0.0 (diff) | |
| download | misskey-d66e4b7ff97d512e2a2523815e2eef170456b37f.tar.gz misskey-d66e4b7ff97d512e2a2523815e2eef170456b37f.tar.bz2 misskey-d66e4b7ff97d512e2a2523815e2eef170456b37f.zip | |
Merge branch 'develop'
Diffstat (limited to 'src/queue/processors/db/export-mute.ts')
| -rw-r--r-- | src/queue/processors/db/export-mute.ts | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/queue/processors/db/export-mute.ts b/src/queue/processors/db/export-mute.ts index 5ded7cf651..b957b48b20 100644 --- a/src/queue/processors/db/export-mute.ts +++ b/src/queue/processors/db/export-mute.ts @@ -1,23 +1,24 @@ import * as Bull from 'bull'; import * as tmp from 'tmp'; import * as fs from 'fs'; -import * as mongo from 'mongodb'; import { queueLogger } from '../../logger'; import addFile from '../../../services/drive/add-file'; -import User from '../../../models/user'; import dateFormat = require('dateformat'); -import Mute from '../../../models/mute'; import { getFullApAccount } from '../../../misc/convert-host'; +import { Users, Mutings } from '../../../models'; +import { MoreThan } from 'typeorm'; const logger = queueLogger.createSubLogger('export-mute'); export async function exportMute(job: Bull.Job, done: any): Promise<void> { - logger.info(`Exporting mute of ${job.data.user._id} ...`); + logger.info(`Exporting mute of ${job.data.user.id} ...`); - const user = await User.findOne({ - _id: new mongo.ObjectID(job.data.user._id.toString()) - }); + const user = await Users.findOne(job.data.user.id); + if (user == null) { + done(); + return; + } // Create temp file const [path, cleanup] = await new Promise<[string, any]>((res, rej) => { @@ -32,30 +33,33 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> { const stream = fs.createWriteStream(path, { flags: 'a' }); let exportedCount = 0; - let ended = false; let cursor: any = null; - while (!ended) { - const mutes = await Mute.find({ - muterId: user._id, - ...(cursor ? { _id: { $gt: cursor } } : {}) - }, { - limit: 100, - sort: { - _id: 1 + while (true) { + const mutes = await Mutings.find({ + where: { + muterId: user.id, + ...(cursor ? { id: MoreThan(cursor) } : {}) + }, + take: 100, + order: { + id: 1 } }); if (mutes.length === 0) { - ended = true; job.progress(100); break; } - cursor = mutes[mutes.length - 1]._id; + cursor = mutes[mutes.length - 1].id; for (const mute of mutes) { - const u = await User.findOne({ _id: mute.muteeId }, { fields: { username: true, host: true } }); + const u = await Users.findOne({ id: mute.muteeId }); + if (u == null) { + exportedCount++; continue; + } + const content = getFullApAccount(u.username, u.host); await new Promise((res, rej) => { stream.write(content + '\n', err => { @@ -70,8 +74,8 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> { exportedCount++; } - const total = await Mute.count({ - muterId: user._id, + const total = await Mutings.count({ + muterId: user.id, }); job.progress(exportedCount / total); @@ -83,7 +87,7 @@ export async function exportMute(job: Bull.Job, done: any): Promise<void> { const fileName = 'mute-' + dateFormat(new Date(), 'yyyy-mm-dd-HH-MM-ss') + '.csv'; const driveFile = await addFile(user, path, fileName); - logger.succ(`Exported to: ${driveFile._id}`); + logger.succ(`Exported to: ${driveFile.id}`); cleanup(); done(); } |