@@ -23,8 +23,8 @@ export class FederatedInstanceService {
|
||||
private idService: IdService,
|
||||
) {
|
||||
this.federatedInstanceCache = new RedisKVCache<Instance | null>(this.redisClient, 'federatedInstance', {
|
||||
lifetime: 1000 * 60 * 60 * 24, // 24h
|
||||
memoryCacheLifetime: 1000 * 60 * 30, // 30m
|
||||
lifetime: 1000 * 60 * 30, // 30m
|
||||
memoryCacheLifetime: 1000 * 60 * 3, // 3m
|
||||
fetcher: (key) => this.instancesRepository.findOneBy({ host: key }),
|
||||
toRedisConverter: (value) => JSON.stringify(value),
|
||||
fromRedisConverter: (value) => {
|
||||
@@ -65,15 +65,10 @@ export class FederatedInstanceService {
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async updateCachePartial(host: string, data: Partial<Instance>): Promise<void> {
|
||||
host = this.utilityService.toPuny(host);
|
||||
public async update(id: Instance['id'], data: Partial<Instance>): Promise<void> {
|
||||
const result = await this.instancesRepository.update(id, data);
|
||||
const updated = result.raw[0];
|
||||
|
||||
const cached = await this.federatedInstanceCache.get(host);
|
||||
if (cached == null) return;
|
||||
|
||||
this.federatedInstanceCache.set(host, {
|
||||
...cached,
|
||||
...data,
|
||||
});
|
||||
this.federatedInstanceCache.set(updated.host, updated);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ import { DI } from '@/di-symbols.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import { HttpRequestService } from '@/core/HttpRequestService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { FederatedInstanceService } from '@/core/FederatedInstanceService';
|
||||
import type { DOMWindow } from 'jsdom';
|
||||
|
||||
type NodeInfo = {
|
||||
@@ -42,6 +43,7 @@ export class FetchInstanceMetadataService {
|
||||
private appLockService: AppLockService,
|
||||
private httpRequestService: HttpRequestService,
|
||||
private loggerService: LoggerService,
|
||||
private federatedInstanceService: FederatedInstanceService,
|
||||
) {
|
||||
this.logger = this.loggerService.getLogger('metadata', 'cyan');
|
||||
}
|
||||
@@ -96,7 +98,7 @@ export class FetchInstanceMetadataService {
|
||||
if (favicon) updates.faviconUrl = favicon;
|
||||
if (themeColor) updates.themeColor = themeColor;
|
||||
|
||||
await this.instancesRepository.update(instance.id, updates);
|
||||
await this.federatedInstanceService.update(instance.id, updates);
|
||||
|
||||
this.logger.succ(`Successfuly updated metadata of ${instance.host}`);
|
||||
} catch (e) {
|
||||
|
Reference in New Issue
Block a user