Compare commits

...

2 commits

Author SHA1 Message Date
2c55f8968c
fixup! server: return report id when reporting
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/test Pipeline failed
2024-03-19 18:46:00 +01:00
fc733a4a86
server: properly expire public key cache
Changelog: Fixed
2024-03-19 18:40:34 +01:00
3 changed files with 17 additions and 13 deletions

View file

@ -1,8 +1,6 @@
import { Cache } from '@/misc/cache.js';
import { UserPublickeys } from '@/models/index.js';
import { IRemoteUser } from '@/models/entities/user.js';
import { UserPublickey } from '@/models/entities/user-publickey.js';
import { uriPersonCache, userByIdCache } from '@/services/user-cache.js';
import { uriPersonCache, userByIdCache, publicKeyCache, publicKeyByUserIdCache } from '@/services/user-cache.js';
import { createPerson } from '@/remote/activitypub/models/person.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { HOUR } from '@/const.js';
@ -12,15 +10,6 @@ export type AuthUser = {
key: UserPublickey;
};
const publicKeyCache = new Cache<UserPublickey>(
2 * HOUR,
(keyId) => UserPublickeys.findOneBy({ keyId }).then(x => x ?? undefined),
);
const publicKeyByUserIdCache = new Cache<UserPublickey>(
2 * HOUR,
(userId) => UserPublickeys.findOneBy({ userId }).then(x => x ?? undefined),
);
function authUserFromApId(uri: string): Promise<AuthUser | null> {
return uriPersonCache.fetch(uri)
.then(async user => {

View file

@ -28,7 +28,7 @@ export const meta = {
nullable: false,
},
}
}
},
errors: ['NO_SUCH_USER', 'CANNOT_REPORT_ADMIN', 'CANNOT_REPORT_YOURSELF'],
} as const;

View file

@ -17,6 +17,15 @@ export const uriPersonCache = new Cache<User>(
15 * MINUTE,
async (uri) => await Users.findOneBy({ uri, isDeleted: IsNull() }) ?? undefined,
);
export const publicKeyCache = new Cache<UserPublickey>(
2 * HOUR,
(keyId) => UserPublickeys.findOneBy({ keyId }).then(x => x ?? undefined),
);
export const publicKeyByUserIdCache = new Cache<UserPublickey>(
2 * HOUR,
(userId) => UserPublickeys.findOneBy({ userId }).then(x => x ?? undefined),
);
subscriber.on('message', async (_, data) => {
const obj = JSON.parse(data);
@ -35,6 +44,12 @@ subscriber.on('message', async (_, data) => {
if (Users.isLocalUser(user)) {
localUserByNativeTokenCache.delete(user.token);
}
// using get here because it does not fetch from the database
const publicKey = publicKeyByUserIdCache.get(user.id);
if (publicKey != null) {
publicKeyByUserIdCache.delete(user.id);
publicKeyCache.delete(publicKey.keyId);
}
} else {
userByIdCache.set(user.id, user);
uriPersonCache.set(user.uri, user);