optimize i/update-remote-user endpoint by fetching from cache

This commit is contained in:
Hazelnoot 2025-07-04 09:53:06 -04:00
parent ed68230811
commit 34dcb1c51c
2 changed files with 29 additions and 2 deletions

View file

@ -7,12 +7,22 @@ import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
import { GetterService } from '@/server/api/GetterService.js';
import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '@/server/api/error.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
errors: {
noSuchUser: {
message: 'No such user.',
code: 'NO_SUCH_USER',
id: '558ea170-f653-4700-94d0-5a818371d0df',
},
},
// Up to 10 calls, then 4 / second.
// This allows for reliable automation.
limit: {
@ -35,9 +45,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
private getterService: GetterService,
private apPersonService: ApPersonService,
private readonly cacheService: CacheService,
) {
super(meta, paramDef, async (ps) => {
const user = await this.getterService.getRemoteUser(ps.userId);
const user = await this.cacheService.findRemoteUserById(ps.userId);
if (!user) {
throw new ApiError(meta.errors.noSuchUser);
}
await this.apPersonService.updatePerson(user.uri!);
});
}