populateEmojisのリファクタと絵文字情報のキャッシュ (#7378)
* revert * Refactor populateEmojis, Cache emojis * ん * fix typo * コメント
This commit is contained in:
parent
2f2a8e537d
commit
d1efe1d208
5 changed files with 89 additions and 216 deletions
|
@ -1,11 +1,11 @@
|
|||
import $ from 'cafy';
|
||||
import { EntityRepository, Repository, In, Not } from 'typeorm';
|
||||
import { User, ILocalUser, IRemoteUser } from '../entities/user';
|
||||
import { Emojis, Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, Antennas, AntennaNotes, ChannelFollowings, Instances } from '..';
|
||||
import { Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, Antennas, AntennaNotes, ChannelFollowings, Instances } from '..';
|
||||
import config from '../../config';
|
||||
import { SchemaType } from '../../misc/schema';
|
||||
import { awaitAll } from '../../prelude/await-all';
|
||||
import { Emoji } from '../entities/emoji';
|
||||
import { populateEmojis } from '../../misc/populate-emojis';
|
||||
|
||||
export type PackedUser = SchemaType<typeof packedUserSchema>;
|
||||
|
||||
|
@ -150,9 +150,6 @@ export class UserRepository extends Repository<User> {
|
|||
options?: {
|
||||
detail?: boolean,
|
||||
includeSecrets?: boolean,
|
||||
_hint_?: {
|
||||
emojis: Emoji[] | null;
|
||||
};
|
||||
}
|
||||
): Promise<PackedUser> {
|
||||
const opts = Object.assign({
|
||||
|
@ -170,34 +167,6 @@ export class UserRepository extends Repository<User> {
|
|||
}) : [];
|
||||
const profile = opts.detail ? await UserProfiles.findOneOrFail(user.id) : null;
|
||||
|
||||
let emojis: Emoji[] = [];
|
||||
if (user.emojis.length > 0) {
|
||||
// 与えられたhintだけで十分(=新たにクエリする必要がない)かどうかを表すフラグ
|
||||
let enough = true;
|
||||
if (options?._hint_?.emojis) {
|
||||
for (const name of user.emojis) {
|
||||
const matched = options._hint_.emojis.find(x => x.name === name && x.host === user.host);
|
||||
if (matched) {
|
||||
emojis.push(matched);
|
||||
} else {
|
||||
enough = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
enough = false;
|
||||
}
|
||||
|
||||
if (!enough) {
|
||||
emojis = await Emojis.find({
|
||||
where: {
|
||||
name: In(user.emojis),
|
||||
host: user.host
|
||||
},
|
||||
select: ['name', 'host', 'url', 'aliases']
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const falsy = opts.detail ? false : undefined;
|
||||
|
||||
const packed = {
|
||||
|
@ -220,9 +189,7 @@ export class UserRepository extends Repository<User> {
|
|||
faviconUrl: instance.faviconUrl,
|
||||
themeColor: instance.themeColor,
|
||||
} : undefined) : undefined,
|
||||
|
||||
// カスタム絵文字添付
|
||||
emojis: emojis,
|
||||
emojis: populateEmojis(user.emojis, user.host),
|
||||
|
||||
...(opts.detail ? {
|
||||
url: profile!.url,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue