diff options
| author | dakkar <dakkar@thenautilus.net> | 2024-11-08 15:52:37 +0000 |
|---|---|---|
| committer | dakkar <dakkar@thenautilus.net> | 2024-11-08 15:52:37 +0000 |
| commit | f079edaf3ccc1fea9242f0f8522ebbfc7e8242e4 (patch) | |
| tree | ead184cf29c147bc74ed92ce905b46e5e42209c1 /packages/backend/src/core/FederatedInstanceService.ts | |
| parent | merge: Bump version number (!735) (diff) | |
| parent | Release: 2024.10.1 (diff) | |
| download | sharkey-f079edaf3ccc1fea9242f0f8522ebbfc7e8242e4.tar.gz sharkey-f079edaf3ccc1fea9242f0f8522ebbfc7e8242e4.tar.bz2 sharkey-f079edaf3ccc1fea9242f0f8522ebbfc7e8242e4.zip | |
Merge tag '2024.10.1' into feature/2024.10
Diffstat (limited to 'packages/backend/src/core/FederatedInstanceService.ts')
| -rw-r--r-- | packages/backend/src/core/FederatedInstanceService.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/packages/backend/src/core/FederatedInstanceService.ts b/packages/backend/src/core/FederatedInstanceService.ts index 7ec565557c..fca3ad847a 100644 --- a/packages/backend/src/core/FederatedInstanceService.ts +++ b/packages/backend/src/core/FederatedInstanceService.ts @@ -49,7 +49,7 @@ export class FederatedInstanceService implements OnApplicationShutdown { } @bindThis - public async fetch(host: string): Promise<MiInstance> { + public async fetchOrRegister(host: string): Promise<MiInstance> { host = this.utilityService.toPuny(host); const cached = await this.federatedInstanceCache.get(host); @@ -86,6 +86,24 @@ export class FederatedInstanceService implements OnApplicationShutdown { } @bindThis + public async fetch(host: string): Promise<MiInstance | null> { + host = this.utilityService.toPuny(host); + + const cached = await this.federatedInstanceCache.get(host); + if (cached !== undefined) return cached; + + const index = await this.instancesRepository.findOneBy({ host }); + + if (index == null) { + this.federatedInstanceCache.set(host, null); + return null; + } else { + this.federatedInstanceCache.set(host, index); + return index; + } + } + + @bindThis public async update(id: MiInstance['id'], data: Partial<MiInstance>): Promise<void> { const result = await this.instancesRepository.createQueryBuilder().update() .set(data) |