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