Skip to content

Commit

Permalink
short cache ttl 12min → 5min
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaina committed Jul 20, 2024
1 parent 5ccc9d6 commit 307e1c4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/backend/src/core/activitypub/ApDbResolverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import type { MiNote } from '@/models/Note.js';
import { bindThis } from '@/decorators.js';
import { MiLocalUser, MiRemoteUser } from '@/models/User.js';
import Logger from '@/logger.js';
import { UtilityService } from '../UtilityService.js';
import { getApId } from './type.js';
import { ApPersonService } from './models/ApPersonService.js';
import { ApLoggerService } from './ApLoggerService.js';
import type { IObject } from './type.js';
import { UtilityService } from '../UtilityService.js';

export type UriParseResult = {
/** wether the URI was generated by us */
Expand Down Expand Up @@ -225,7 +225,7 @@ export class ApDbResolverService implements OnApplicationShutdown {
* If not found with keyId, update cache and reacquire
*/
const cacheRaw = this.publicKeyByUserIdCache.cache.get(user.id);
if (cacheRaw && cacheRaw.date > Date.now() - 1000 * 60 * 12) {
if (cacheRaw && Date.now() - cacheRaw.date > 1000 * 60 * 5) {
const exactKey = await this.refreshAndFindKey(user.id, keyId);
if (exactKey) return { user, key: exactKey };
}
Expand All @@ -234,7 +234,7 @@ export class ApDbResolverService implements OnApplicationShutdown {
* lastFetchedAtでの更新制限を弱めて再取得
* Reacquisition with weakened update limit at lastFetchedAt
*/
if (user.lastFetchedAt == null || user.lastFetchedAt < new Date(Date.now() - 1000 * 60 * 12)) {
if (user.lastFetchedAt == null || Date.now() - user.lastFetchedAt.getTime() > 1000 * 60 * 5) {
this.logger.info(`Fetching user to find public key uri=${uri} userId=${user.id} keyId=${keyId}`);
const renewed = await this.apPersonService.fetchPersonWithRenewal(uri, 0);
if (renewed == null || renewed.isDeleted) return null;
Expand Down

0 comments on commit 307e1c4

Please sign in to comment.