Skip to content

Commit

Permalink
updateHashtagを並列で行わないように (misskey-dev#5284)
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 authored and syuilo committed Aug 18, 2019
1 parent fc78c75 commit 7ecfc00
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/remote/activitypub/models/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ITag, extractHashtags } from './tag';
import { IIdentifier } from './identifier';
import { apLogger } from '../logger';
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 { User, IRemoteUser } from '../../../models/entities/user';
import { Emoji } from '../../../models/entities/emoji';
Expand Down Expand Up @@ -194,8 +194,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
usersChart.update(user!, true);

// ハッシュタグ更新
for (const tag of tags) updateHashtag(user!, tag, true, true);
for (const tag of (user!.tags || []).filter(x => !tags.includes(x))) updateHashtag(user!, tag, true, false);
updateUsertags(user!, tags);

//#region アイコンとヘッダー画像をフェッチ
const [avatar, banner] = (await Promise.all<DriveFile | null>([
Expand Down Expand Up @@ -355,8 +354,7 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
});

// ハッシュタグ更新
for (const tag of tags) updateHashtag(exist, tag, true, true);
for (const tag of (exist.tags || []).filter(x => !tags.includes(x))) updateHashtag(exist, tag, true, false);
updateUsertags(exist, tags);

// 該当ユーザーが既にフォロワーになっていた場合はFollowingもアップデートする
await Followings.update({
Expand Down
5 changes: 2 additions & 3 deletions src/server/api/endpoints/i/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { parse, parsePlain } from '../../../../mfm/parse';
import extractEmojis from '../../../../misc/extract-emojis';
import extractHashtags from '../../../../misc/extract-hashtags';
import * as langmap from 'langmap';
import { updateHashtag } from '../../../../services/update-hashtag';
import { updateUsertags } from '../../../../services/update-hashtag';
import { ApiError } from '../../error';
import { Users, DriveFiles, UserProfiles, Pages } from '../../../../models';
import { User } from '../../../../models/entities/user';
Expand Down Expand Up @@ -264,8 +264,7 @@ export default define(meta, async (ps, user, app) => {
updates.tags = tags;

// ハッシュタグ更新
for (const tag of tags) updateHashtag(user, tag, true, true);
for (const tag of user.tags.filter(x => !tags.includes(x))) updateHashtag(user, tag, true, false);
updateUsertags(user, tags);
//#endregion

if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
Expand Down
4 changes: 2 additions & 2 deletions src/services/note/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import watch from './watch';
import { parse } from '../../mfm/parse';
import { resolveUser } from '../../remote/resolve-user';
import config from '../../config';
import { updateHashtag } from '../update-hashtag';
import { updateHashtags } from '../update-hashtag';
import { concat } from '../../prelude/array';
import insertNoteUnread from './unread';
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc';
Expand Down Expand Up @@ -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)
incNotesCountOfUser(user);
Expand Down
16 changes: 16 additions & 0 deletions src/services/update-hashtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ import { hashtagChart } from './chart';
import { genId } from '../misc/gen-id';
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) {
tag = tag.toLowerCase();

Expand Down

0 comments on commit 7ecfc00

Please sign in to comment.