From 63b1689155f2bf81f6d034a78ab0aad609e76fd2 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 6 Apr 2019 00:41:08 +0900 Subject: [PATCH] Fix #4556 (#4558) --- src/queue/processors/db/import-following.ts | 48 +++++++++++++-------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/queue/processors/db/import-following.ts b/src/queue/processors/db/import-following.ts index a1242b71c8..069afa74c4 100644 --- a/src/queue/processors/db/import-following.ts +++ b/src/queue/processors/db/import-following.ts @@ -28,29 +28,41 @@ export async function importFollowing(job: Bull.Job, done: any): Promise { const csv = await downloadTextFile(url); + let linenum = 0; + for (const line of csv.trim().split('\n')) { - const { username, host } = parseAcct(line.trim()); + linenum++; - let target = isSelfHost(host) ? await User.findOne({ - host: null, - usernameLower: username.toLowerCase() - }) : await User.findOne({ - host: toDbHost(host), - usernameLower: username.toLowerCase() - }); + try { + const { username, host } = parseAcct(line.trim()); - if (host == null && target == null) continue; + let target = isSelfHost(host) ? await User.findOne({ + host: null, + usernameLower: username.toLowerCase() + }) : await User.findOne({ + host: toDbHost(host), + usernameLower: username.toLowerCase() + }); - if (target == null) { - target = await resolveUser(username, host); + if (host == null && target == null) continue; + + if (target == null) { + target = await resolveUser(username, host); + } + + if (target == null) { + throw `cannot resolve user: @${username}@${host}`; + } + + // skip myself + if (target._id.equals(job.data.user._id)) continue; + + logger.info(`Follow[${linenum}] ${target._id} ...`); + + follow(user, target); + } catch (e) { + logger.warn(`Error in line:${linenum} ${e}`); } - - // skip myself - if (target._id.equals(job.data.user._id)) continue; - - logger.info(`Follow ${target._id} ...`); - - follow(user, target); } logger.succ('Imported');