forked from FoundKeyGang/FoundKey
remove duplicated cache
A cache for instances already exists and is exported there. Also the type annotation here seemed wrong anyway because there did not seem to be a way for that fetcher to actually ever return `null` as a value.
This commit is contained in:
parent
2218936af3
commit
e2779befe6
1 changed files with 2 additions and 6 deletions
|
@ -8,14 +8,10 @@ import { populateEmojis } from '@/misc/populate-emojis.js';
|
|||
import { USER_ACTIVE_THRESHOLD, USER_ONLINE_THRESHOLD, HOUR } from '@/const.js';
|
||||
import { Cache } from '@/misc/cache.js';
|
||||
import { db } from '@/db/postgre.js';
|
||||
import { registerOrFetchInstanceDoc } from '@/services/register-or-fetch-instance-doc.js';
|
||||
import { Instance } from '../entities/instance.js';
|
||||
import { Notes, NoteUnreads, FollowRequests, Notifications, MessagingMessages, UserNotePinings, Followings, Blockings, Mutings, RenoteMutings, UserProfiles, UserSecurityKeys, UserGroupJoinings, Pages, Announcements, AnnouncementReads, AntennaNotes, ChannelFollowings, Instances, DriveFiles } from '../index.js';
|
||||
|
||||
const userInstanceCache = new Cache<Instance | null>(
|
||||
3 * HOUR,
|
||||
(host) => Instances.findOneBy({ host }).then(x => x ?? undefined),
|
||||
);
|
||||
|
||||
type IsUserDetailed<Detailed extends boolean> = Detailed extends true ? Packed<'UserDetailed'> : Packed<'UserLite'>;
|
||||
type IsMeAndIsUserDetailed<ExpectsMe extends boolean | null, Detailed extends boolean> =
|
||||
Detailed extends true ?
|
||||
|
@ -319,7 +315,7 @@ export const UserRepository = db.getRepository(User).extend({
|
|||
isModerator: user.isModerator,
|
||||
isBot: user.isBot,
|
||||
isCat: user.isCat,
|
||||
instance: !user.host ? undefined : userInstanceCache.fetch(user.host)
|
||||
instance: !user.host ? undefined : registerOrFetchInstanceDoc(user.host)
|
||||
.then(instance => !instance ? undefined : {
|
||||
name: instance.name,
|
||||
softwareName: instance.softwareName,
|
||||
|
|
Loading…
Reference in a new issue