Compare commits
2 commits
5636534d03
...
2c55f8968c
Author | SHA1 | Date | |
---|---|---|---|
2c55f8968c | |||
fc733a4a86 |
3 changed files with 17 additions and 13 deletions
|
@ -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 => {
|
||||
|
|
|
@ -28,7 +28,7 @@ export const meta = {
|
|||
nullable: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
errors: ['NO_SUCH_USER', 'CANNOT_REPORT_ADMIN', 'CANNOT_REPORT_YOURSELF'],
|
||||
} as const;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue