mirror of
https://github.com/docmost/docmost.git
synced 2026-08-24 21:42:15 +10:00
fix(integration): purge per-user unfurl cache on disconnect
This commit is contained in:
@@ -2,12 +2,14 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
|||||||
import { IntegrationConnectionRepo } from './repos/integration-connection.repo';
|
import { IntegrationConnectionRepo } from './repos/integration-connection.repo';
|
||||||
import { IntegrationRepo } from './repos/integration.repo';
|
import { IntegrationRepo } from './repos/integration.repo';
|
||||||
import { IntegrationConnection } from '@docmost/db/types/entity.types';
|
import { IntegrationConnection } from '@docmost/db/types/entity.types';
|
||||||
|
import { UnfurlService } from './unfurl/unfurl.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class IntegrationConnectionService {
|
export class IntegrationConnectionService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly connectionRepo: IntegrationConnectionRepo,
|
private readonly connectionRepo: IntegrationConnectionRepo,
|
||||||
private readonly integrationRepo: IntegrationRepo,
|
private readonly integrationRepo: IntegrationRepo,
|
||||||
|
private readonly unfurlService: UnfurlService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async getConnectionStatus(
|
async getConnectionStatus(
|
||||||
@@ -79,5 +81,7 @@ export class IntegrationConnectionService {
|
|||||||
integrationId,
|
integrationId,
|
||||||
userId,
|
userId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await this.unfurlService.purgeUserCache(workspaceId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,6 +113,22 @@ export class UnfurlService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async purgeUserCache(workspaceId: string, userId: string): Promise<void> {
|
||||||
|
const pattern = `${UNFURL_CACHE_PREFIX}${workspaceId}:${userId}:*`;
|
||||||
|
try {
|
||||||
|
const stream = this.redis.scanStream({ match: pattern, count: 100 });
|
||||||
|
for await (const keys of stream as AsyncIterable<string[]>) {
|
||||||
|
if (keys.length) {
|
||||||
|
await this.redis.unlink(...keys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to purge unfurl cache for user ${userId}: ${(err as Error).message}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private buildNeedsConnection(
|
private buildNeedsConnection(
|
||||||
provider: IntegrationProvider,
|
provider: IntegrationProvider,
|
||||||
integrationId: string,
|
integrationId: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user