mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-27 22:39:33 +09:00
Merge branch 'fix-fedupdlck' into ed25519
This commit is contained in:
commit
862ebe23af
@ -56,23 +56,33 @@ export class FetchInstanceMetadataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async tryLock(host: string): Promise<boolean> {
|
private async tryLock(host: string): Promise<string | null> {
|
||||||
const mutex = await this.redisClient.set(`fetchInstanceMetadata:mutex:${host}`, '1', 'GET');
|
// TODO: マイグレーションなのであとで消す (2024.3.1)
|
||||||
return mutex !== '1';
|
this.redisClient.del(`fetchInstanceMetadata:mutex:${host}`);
|
||||||
|
|
||||||
|
return await this.redisClient.set(
|
||||||
|
`fetchInstanceMetadata:mutex:v2:${host}`, '1',
|
||||||
|
'EX', 30, // 30秒したら自動でロック解除 https://github.com/misskey-dev/misskey/issues/13506#issuecomment-1975375395
|
||||||
|
'GET' // 古い値を返す(なかったらnull)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public unlock(host: string): Promise<'OK'> {
|
private unlock(host: string): Promise<number> {
|
||||||
return this.redisClient.set(`fetchInstanceMetadata:mutex:${host}`, '0');
|
return this.redisClient.del(`fetchInstanceMetadata:mutex:v2:${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
|
|
||||||
if (!await this.tryLock(host)) return;
|
|
||||||
try {
|
try {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
|
if (await this.tryLock(host) === '1') {
|
||||||
|
// 1が返ってきていたらロックされている = 何もしない
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const _instance = await this.federatedInstanceService.fetch(host);
|
const _instance = await this.federatedInstanceService.fetch(host);
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (_instance && _instance.infoUpdatedAt && (now - _instance.infoUpdatedAt.getTime() < REMOTE_SERVER_CACHE_TTL)) {
|
if (_instance && _instance.infoUpdatedAt && (now - _instance.infoUpdatedAt.getTime() < REMOTE_SERVER_CACHE_TTL)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user