server: don't cache users for infinity
Some checks failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline failed
Some checks failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline failed
If the cache runs for an infinite amount of time, the users may as well be stored in memory directly. Changelog: Fixed
This commit is contained in:
parent
8d78113907
commit
101ea21747
|
@ -2,9 +2,10 @@ import { UserKeypairs } from '@/models/index.js';
|
||||||
import { User } from '@/models/entities/user.js';
|
import { User } from '@/models/entities/user.js';
|
||||||
import { UserKeypair } from '@/models/entities/user-keypair.js';
|
import { UserKeypair } from '@/models/entities/user-keypair.js';
|
||||||
import { Cache } from './cache.js';
|
import { Cache } from './cache.js';
|
||||||
|
import { MINUTE } from '@/const.js';
|
||||||
|
|
||||||
const cache = new Cache<UserKeypair>(
|
const cache = new Cache<UserKeypair>(
|
||||||
Infinity,
|
15 * MINUTE,
|
||||||
(userId) => UserKeypairs.findOneByOrFail({ userId }),
|
(userId) => UserKeypairs.findOneByOrFail({ userId }),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,18 @@ import { ILocalUser, User } from '@/models/entities/user.js';
|
||||||
import { Users } from '@/models/index.js';
|
import { Users } from '@/models/index.js';
|
||||||
import { Cache } from '@/misc/cache.js';
|
import { Cache } from '@/misc/cache.js';
|
||||||
import { subscriber } from '@/db/redis.js';
|
import { subscriber } from '@/db/redis.js';
|
||||||
|
import { MINUTE } from '@/const.js';
|
||||||
|
|
||||||
export const userByIdCache = new Cache<User>(
|
export const userByIdCache = new Cache<User>(
|
||||||
Infinity,
|
15 * MINUTE,
|
||||||
async (id) => await Users.findOneBy({ id, isDeleted: IsNull() }) ?? undefined,
|
async (id) => await Users.findOneBy({ id, isDeleted: IsNull() }) ?? undefined,
|
||||||
);
|
);
|
||||||
export const localUserByNativeTokenCache = new Cache<ILocalUser>(
|
export const localUserByNativeTokenCache = new Cache<ILocalUser>(
|
||||||
Infinity,
|
15 * MINUTE,
|
||||||
async (token) => await Users.findOneBy({ token, host: IsNull(), isDeleted: IsNull() }) as ILocalUser | null ?? undefined,
|
async (token) => await Users.findOneBy({ token, host: IsNull(), isDeleted: IsNull() }) as ILocalUser | null ?? undefined,
|
||||||
);
|
);
|
||||||
export const uriPersonCache = new Cache<User>(
|
export const uriPersonCache = new Cache<User>(
|
||||||
Infinity,
|
15 * MINUTE,
|
||||||
async (uri) => await Users.findOneBy({ uri, isDeleted: IsNull() }) ?? undefined,
|
async (uri) => await Users.findOneBy({ uri, isDeleted: IsNull() }) ?? undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue