updateHashtagを並列で行わないように (#5284)

This commit is contained in:
MeiMei 2019-08-18 12:47:45 +09:00 committed by syuilo
parent fc78c75bab
commit 7ecfc007a9
4 changed files with 23 additions and 10 deletions

View file

@ -12,7 +12,7 @@ import { ITag, extractHashtags } from './tag';
import { IIdentifier } from './identifier'; import { IIdentifier } from './identifier';
import { apLogger } from '../logger'; import { apLogger } from '../logger';
import { Note } from '../../../models/entities/note'; import { Note } from '../../../models/entities/note';
import { updateHashtag } from '../../../services/update-hashtag'; import { updateUsertags } from '../../../services/update-hashtag';
import { Users, UserNotePinings, Instances, DriveFiles, Followings, UserProfiles, UserPublickeys } from '../../../models'; import { Users, UserNotePinings, Instances, DriveFiles, Followings, UserProfiles, UserPublickeys } from '../../../models';
import { User, IRemoteUser } from '../../../models/entities/user'; import { User, IRemoteUser } from '../../../models/entities/user';
import { Emoji } from '../../../models/entities/emoji'; import { Emoji } from '../../../models/entities/emoji';
@ -194,8 +194,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
usersChart.update(user!, true); usersChart.update(user!, true);
// ハッシュタグ更新 // ハッシュタグ更新
for (const tag of tags) updateHashtag(user!, tag, true, true); updateUsertags(user!, tags);
for (const tag of (user!.tags || []).filter(x => !tags.includes(x))) updateHashtag(user!, tag, true, false);
//#region アイコンとヘッダー画像をフェッチ //#region アイコンとヘッダー画像をフェッチ
const [avatar, banner] = (await Promise.all<DriveFile | null>([ const [avatar, banner] = (await Promise.all<DriveFile | null>([
@ -355,8 +354,7 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
}); });
// ハッシュタグ更新 // ハッシュタグ更新
for (const tag of tags) updateHashtag(exist, tag, true, true); updateUsertags(exist, tags);
for (const tag of (exist.tags || []).filter(x => !tags.includes(x))) updateHashtag(exist, tag, true, false);
// 該当ユーザーが既にフォロワーになっていた場合はFollowingもアップデートする // 該当ユーザーが既にフォロワーになっていた場合はFollowingもアップデートする
await Followings.update({ await Followings.update({

View file

@ -8,7 +8,7 @@ import { parse, parsePlain } from '../../../../mfm/parse';
import extractEmojis from '../../../../misc/extract-emojis'; import extractEmojis from '../../../../misc/extract-emojis';
import extractHashtags from '../../../../misc/extract-hashtags'; import extractHashtags from '../../../../misc/extract-hashtags';
import * as langmap from 'langmap'; import * as langmap from 'langmap';
import { updateHashtag } from '../../../../services/update-hashtag'; import { updateUsertags } from '../../../../services/update-hashtag';
import { ApiError } from '../../error'; import { ApiError } from '../../error';
import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models'; import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models';
import { User } from '../../../../models/entities/user'; import { User } from '../../../../models/entities/user';
@ -264,8 +264,7 @@ export default define(meta, async (ps, user, app) => {
updates.tags = tags; updates.tags = tags;
// ハッシュタグ更新 // ハッシュタグ更新
for (const tag of tags) updateHashtag(user, tag, true, true); updateUsertags(user, tags);
for (const tag of user.tags.filter(x => !tags.includes(x))) updateHashtag(user, tag, true, false);
//#endregion //#endregion
if (Object.keys(updates).length > 0) await Users.update(user.id, updates); if (Object.keys(updates).length > 0) await Users.update(user.id, updates);

View file

@ -9,7 +9,7 @@ import watch from './watch';
import { parse } from '../../mfm/parse'; import { parse } from '../../mfm/parse';
import { resolveUser } from '../../remote/resolve-user'; import { resolveUser } from '../../remote/resolve-user';
import config from '../../config'; import config from '../../config';
import { updateHashtag } from '../update-hashtag'; import { updateHashtags } from '../update-hashtag';
import { concat } from '../../prelude/array'; import { concat } from '../../prelude/array';
import insertNoteUnread from './unread'; import insertNoteUnread from './unread';
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc'; import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc';
@ -202,7 +202,7 @@ export default async (user: User, data: Option, silent = false) => new Promise<N
} }
// ハッシュタグ更新 // ハッシュタグ更新
for (const tag of tags) updateHashtag(user, tag); updateHashtags(user, tags);
// Increment notes count (user) // Increment notes count (user)
incNotesCountOfUser(user); incNotesCountOfUser(user);

View file

@ -4,6 +4,22 @@ import { hashtagChart } from './chart';
import { genId } from '../misc/gen-id'; import { genId } from '../misc/gen-id';
import { Hashtag } from '../models/entities/hashtag'; import { Hashtag } from '../models/entities/hashtag';
export async function updateHashtags(user: User, tags: string[]) {
for (const tag of tags) {
await updateHashtag(user, tag);
}
}
export async function updateUsertags(user: User, tags: string[]) {
for (const tag of tags) {
await updateHashtag(user, tag, true, true);
}
for (const tag of (user.tags || []).filter(x => !tags.includes(x))) {
await updateHashtag(user, tag, true, false);
}
}
export async function updateHashtag(user: User, tag: string, isUserAttached = false, inc = true) { export async function updateHashtag(user: User, tag: string, isUserAttached = false, inc = true) {
tag = tag.toLowerCase(); tag = tag.toLowerCase();