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

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:
Johann150 2023-11-04 11:54:13 +01:00
parent 8d78113907
commit 101ea21747
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 6 additions and 4 deletions

View file

@ -2,9 +2,10 @@ import { UserKeypairs } from '@/models/index.js';
import { User } from '@/models/entities/user.js';
import { UserKeypair } from '@/models/entities/user-keypair.js';
import { Cache } from './cache.js';
import { MINUTE } from '@/const.js';
const cache = new Cache<UserKeypair>(
Infinity,
15 * MINUTE,
(userId) => UserKeypairs.findOneByOrFail({ userId }),
);

View file

@ -3,17 +3,18 @@ import { 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';
import { MINUTE } from '@/const.js';
export const userByIdCache = new Cache<User>(
Infinity,
15 * MINUTE,
async (id) => await Users.findOneBy({ id, isDeleted: IsNull() }) ?? undefined,
);
export const localUserByNativeTokenCache = new Cache<ILocalUser>(
Infinity,
15 * MINUTE,
async (token) => await Users.findOneBy({ token, host: IsNull(), isDeleted: IsNull() }) as ILocalUser | null ?? undefined,
);
export const uriPersonCache = new Cache<User>(
Infinity,
15 * MINUTE,
async (uri) => await Users.findOneBy({ uri, isDeleted: IsNull() }) ?? undefined,
);