mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 22:39:33 +09:00
頻繁にAPリクエストが発生するサーバーに対してfetchInstanceMetadata手動更新が無視される問題を修正 (MisskeyIO#194)
This commit is contained in:
parent
239d9a4c81
commit
42bc2817be
@ -52,20 +52,20 @@ export class FetchInstanceMetadataService {
|
||||
|
||||
@bindThis
|
||||
public async tryLock(host: string): Promise<boolean> {
|
||||
const mutex = await this.redisClient.set(`fetchInstanceMetadata:mutex:${host}`, '1', 'EX', 60 * 5, 'NX', 'GET');
|
||||
return mutex !== '1';
|
||||
const mutex = await this.redisClient.set(`fetchInstanceMetadata:mutex:${host}`, Date.now(), 'EX', 60 * 5, 'NX');
|
||||
return mutex !== null;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public unlock(host: string): Promise<number> {
|
||||
return this.redisClient.del(`fetchInstanceMetadata:mutex:${host}`);
|
||||
return this.redisClient.unlink(`fetchInstanceMetadata:mutex:${host}`);
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public async fetchInstanceMetadata(instance: MiInstance, force = false): Promise<void> {
|
||||
const host = instance.host;
|
||||
// Acquire mutex to ensure no parallel runs
|
||||
if (!await this.tryLock(host)) return;
|
||||
if (!await this.tryLock(host) && !force) return;
|
||||
try {
|
||||
if (!force) {
|
||||
const _instance = await this.federatedInstanceService.fetch(host);
|
||||
|
@ -23,9 +23,10 @@ import type { MockFunctionMetadata } from 'jest-mock';
|
||||
function mockRedis() {
|
||||
const hash = {};
|
||||
const set = jest.fn((key, value) => {
|
||||
const ret = hash[key];
|
||||
// このテストで呼び出すSETにはNXオプションが付いてる
|
||||
if (hash[key]) return null;
|
||||
hash[key] = value;
|
||||
return ret;
|
||||
return 'OK';
|
||||
});
|
||||
return set;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user