diff options
Diffstat (limited to 'src/queue/processors/db/export-following.ts')
| -rw-r--r-- | src/queue/processors/db/export-following.ts | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/queue/processors/db/export-following.ts b/src/queue/processors/db/export-following.ts index 019414072a..fb30df79fe 100644 --- a/src/queue/processors/db/export-following.ts +++ b/src/queue/processors/db/export-following.ts @@ -1,22 +1,21 @@ 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 Following from '../../../models/following'; import { getFullApAccount } from '../../../misc/convert-host'; +import { Users, Followings } from '../../../models'; +import { MoreThan } from 'typeorm'; const logger = queueLogger.createSubLogger('export-following'); export async function exportFollowing(job: Bull.Job, done: any): Promise<void> { - logger.info(`Exporting following of ${job.data.user._id} ...`); + logger.info(`Exporting following of ${job.data.user.id} ...`); - const user = await User.findOne({ - _id: new mongo.ObjectID(job.data.user._id.toString()) + const user = await Users.findOne({ + id: job.data.user.id }); // Create temp file @@ -36,13 +35,14 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> { let cursor: any = null; while (!ended) { - const followings = await Following.find({ - followerId: user._id, - ...(cursor ? { _id: { $gt: cursor } } : {}) - }, { - limit: 100, - sort: { - _id: 1 + const followings = await Followings.find({ + where: { + followerId: user.id, + ...(cursor ? { id: MoreThan(cursor) } : {}) + }, + take: 100, + order: { + id: 1 } }); @@ -52,10 +52,10 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> { break; } - cursor = followings[followings.length - 1]._id; + cursor = followings[followings.length - 1].id; for (const following of followings) { - const u = await User.findOne({ _id: following.followeeId }, { fields: { username: true, host: true } }); + const u = await Users.findOne({ id: following.followeeId }); const content = getFullApAccount(u.username, u.host); await new Promise((res, rej) => { stream.write(content + '\n', err => { @@ -70,8 +70,8 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> { exportedCount++; } - const total = await Following.count({ - followerId: user._id, + const total = await Followings.count({ + followerId: user.id, }); job.progress(exportedCount / total); @@ -83,7 +83,7 @@ export async function exportFollowing(job: Bull.Job, done: any): Promise<void> { const fileName = 'following-' + 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(); } |