remove duplicated cache
ci/woodpecker/push/build Pipeline was successful Details
ci/woodpecker/push/lint-sw Pipeline failed Details
ci/woodpecker/push/lint-foundkey-js Pipeline was successful Details
ci/woodpecker/push/lint-client Pipeline failed Details
ci/woodpecker/push/lint-backend Pipeline failed Details
ci/woodpecker/push/test Pipeline failed Details

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:
Johann150 2024-03-30 23:31:47 +01:00
parent 2218936af3
commit e2779befe6
Signed by: Johann150
GPG Key ID: 9EE6577A2A06F8F1
1 changed files with 2 additions and 6 deletions

View File

@ -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,