From 98b8a94f2bf2c1d64c88eadf8c10af1e5d1590a9 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sun, 21 Apr 2019 23:56:56 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88?= =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE=E4=BF=AE=E5=BE=A9?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=8C=E8=87=AA=E5=8B=95=E7=9A=84=E3=81=AB?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=20for=20?= =?UTF-8?q?v10=20(#4763)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix: ユーザーresyncが自動実行されない * ここにあっても意味がない * lastFetchedAt事前更新はWebFingerする前のみ * lint fix --- src/remote/activitypub/models/person.ts | 7 ------- src/remote/resolve-user.ts | 18 +++++++++++++----- src/server/api/endpoints/users/show.ts | 9 +-------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 570e92d73..2995e1dbb 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -294,13 +294,6 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: obje } //#endregion - // 繋がらないインスタンスに何回も試行するのを防ぐ, 後続の同様処理の連続試行を防ぐ ため 試行前にも更新する - await User.update({ _id: exist._id }, { - $set: { - lastFetchedAt: new Date(), - }, - }); - if (resolver == null) resolver = new Resolver(); const object = hint || await resolver.resolve(uri) as any; diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts index df5aee7a0..767eb89b7 100644 --- a/src/remote/resolve-user.ts +++ b/src/remote/resolve-user.ts @@ -9,7 +9,7 @@ import chalk from 'chalk'; const logger = remoteLogger.createSubLogger('resolve-user'); -export default async (username: string, _host: string, option?: any, resync?: boolean): Promise => { +export default async (username: string, _host: string, option?: any, resync = false): Promise => { const usernameLower = username.toLowerCase(); if (_host == null) { @@ -28,7 +28,7 @@ export default async (username: string, _host: string, option?: any, resync?: bo return await User.findOne({ usernameLower, host: null }); } - const user = await User.findOne({ usernameLower, host }, option); + const user = await User.findOne({ usernameLower, host }, option) as IRemoteUser; const acctLower = `${usernameLower}@${hostAscii}`; @@ -39,14 +39,22 @@ export default async (username: string, _host: string, option?: any, resync?: bo return await createPerson(self.href); } - if (resync) { + // resyncオプション OR ユーザー情報が古い場合は、WebFilgerからやりなおして返す + if (resync || user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) { + // 繋がらないインスタンスに何回も試行するのを防ぐ, 後続の同様処理の連続試行を防ぐ ため 試行前にも更新する + await User.update({ _id: user._id }, { + $set: { + lastFetchedAt: new Date(), + }, + }); + logger.info(`try resync: ${acctLower}`); const self = await resolveSelf(acctLower); - if ((user as IRemoteUser).uri !== self.href) { + if (user.uri !== self.href) { // if uri mismatch, Fix (user@host <=> AP's Person id(IRemoteUser.uri)) mapping. logger.info(`uri missmatch: ${acctLower}`); - logger.info(`recovery missmatch uri for (username=${username}, host=${host}) from ${(user as IRemoteUser).uri} to ${self.href}`); + logger.info(`recovery missmatch uri for (username=${username}, host=${host}) from ${user.uri} to ${self.href}`); // validate uri const uri = new URL(self.href); diff --git a/src/server/api/endpoints/users/show.ts b/src/server/api/endpoints/users/show.ts index 4e59945eb..4561c5f1d 100644 --- a/src/server/api/endpoints/users/show.ts +++ b/src/server/api/endpoints/users/show.ts @@ -1,6 +1,6 @@ import $ from 'cafy'; import ID, { transform, transformMany } from '../../../../misc/cafy-id'; -import User, { pack, isRemoteUser } from '../../../../models/user'; +import User, { pack } from '../../../../models/user'; import resolveRemoteUser from '../../../../remote/resolve-user'; import define from '../../define'; import { apiLogger } from '../../logger'; @@ -96,13 +96,6 @@ export default define(meta, async (ps, me) => { throw new ApiError(meta.errors.noSuchUser); } - // ユーザー情報更新 - if (isRemoteUser(user)) { - if (user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) { - resolveRemoteUser(ps.username, ps.host, { }, true); - } - } - return await pack(user, me, { detail: true });