diff --git a/packages/backend/src/models/entities/user.ts b/packages/backend/src/models/entities/user.ts index dd2598322..ae905c580 100644 --- a/packages/backend/src/models/entities/user.ts +++ b/packages/backend/src/models/entities/user.ts @@ -214,7 +214,7 @@ export class User { @Index({ unique: true }) @Column('char', { length: 16, nullable: true, unique: true, - comment: 'The native access token of the User. It will be null if the origin of the user is local.', + comment: 'The native access token of local users, or null.', }) public token: string | null; @@ -234,10 +234,12 @@ export class User { export interface ILocalUser extends User { host: null; + token: string; } export interface IRemoteUser extends User { host: string; + token: null; } export type CacheableLocalUser = ILocalUser; diff --git a/packages/backend/src/models/repositories/user.ts b/packages/backend/src/models/repositories/user.ts index 00dcf7f87..13ddfd428 100644 --- a/packages/backend/src/models/repositories/user.ts +++ b/packages/backend/src/models/repositories/user.ts @@ -35,7 +35,7 @@ const locationSchema = { type: 'string', minLength: 1, maxLength: 50 } as const; const birthdaySchema = { type: 'string', pattern: /^([0-9]{4})-([0-9]{2})-([0-9]{2})$/.toString().slice(1, -1) } as const; function isLocalUser(user: User): user is ILocalUser; -function isLocalUser(user: T): user is T & { host: null; }; +function isLocalUser(user: T): user is T & { host: null; token: string; }; function isLocalUser(user: User | { host: User['host'] }): boolean { return user.host == null; } diff --git a/packages/backend/src/services/user-cache.ts b/packages/backend/src/services/user-cache.ts index 2d2ec5711..1266ef5f0 100644 --- a/packages/backend/src/services/user-cache.ts +++ b/packages/backend/src/services/user-cache.ts @@ -1,10 +1,10 @@ import { IsNull } from 'typeorm'; -import { CacheableLocalUser, CacheableUser, ILocalUser } from '@/models/entities/user.js'; +import { CacheableLocalUser, ILocalUser, User } from '@/models/entities/user.js'; import { Users } from '@/models/index.js'; import { Cache } from '@/misc/cache.js'; import { subscriber } from '@/db/redis.js'; -export const userByIdCache = new Cache( +export const userByIdCache = new Cache( Infinity, async (id) => await Users.findOneBy({ id }) ?? undefined, ); @@ -12,7 +12,7 @@ export const localUserByNativeTokenCache = new Cache( Infinity, async (token) => await Users.findOneBy({ token, host: IsNull() }) as ILocalUser | null ?? undefined, ); -export const uriPersonCache = new Cache( +export const uriPersonCache = new Cache( Infinity, async (uri) => await Users.findOneBy({ uri }) ?? undefined, );