Skip to content

Commit 9bb667a

Browse files
committed
Enhance: Emojiのキャッシュを使用するように
1 parent 7053120 commit 9bb667a

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

  • packages/backend/src/server/api/endpoints

packages/backend/src/server/api/endpoints/emojis.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
* SPDX-License-Identifier: AGPL-3.0-only
44
*/
55

6-
import { IsNull } from 'typeorm';
7-
import { Inject, Injectable } from '@nestjs/common';
8-
import type { EmojisRepository } from '@/models/_.js';
6+
import { Injectable } from '@nestjs/common';
97
import { Endpoint } from '@/server/api/endpoint-base.js';
8+
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
109
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
11-
import { DI } from '@/di-symbols.js';
1210

1311
export const meta = {
1412
tags: ['meta'],
@@ -44,21 +42,23 @@ export const paramDef = {
4442
@Injectable()
4543
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
4644
constructor(
47-
@Inject(DI.emojisRepository)
48-
private emojisRepository: EmojisRepository,
49-
45+
private customEmojiService: CustomEmojiService,
5046
private emojiEntityService: EmojiEntityService,
5147
) {
5248
super(meta, paramDef, async (ps, me) => {
53-
const emojis = await this.emojisRepository.find({
54-
where: {
55-
host: IsNull(),
56-
},
57-
order: {
58-
category: 'ASC',
59-
name: 'ASC',
60-
},
61-
});
49+
const emojis = Array.from((await this.customEmojiService.localEmojisCache.fetch()).values())
50+
.sort((a, b) => {
51+
if (a.category === null && b.category !== null) return 1;
52+
if (a.category !== null && b.category === null) return -1;
53+
if (a.category !== null && b.category !== null) {
54+
if (a.category < b.category) return -1;
55+
if (a.category > b.category) return 1;
56+
}
57+
58+
if (a.name < b.name) return -1;
59+
if (a.name > b.name) return 1;
60+
return 0;
61+
});
6262

6363
return {
6464
emojis: await this.emojiEntityService.packSimpleMany(emojis),

0 commit comments

Comments
 (0)