Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix caching system

Matheus Nogueiraf85e0acea0ac
diff --git a/backend/src/ee/services/insights/insights-service.ts b/backend/src/ee/services/insights/insights-service.ts
index 348ccded34..64e71b56ce 100644
--- a/backend/src/ee/services/insights/insights-service.ts
+++ b/backend/src/ee/services/insights/insights-service.ts
@@ -502,19 +502,21 @@ export const insightsServiceFactory = ({
dto.projectId,
`secrets-duplication:${dto.offset ?? 0}:${dto.limit ?? 50}`
);
+
+ const project = await projectDAL.findById(dto.projectId);
+
+ if (!project.secretBlindIndexEnabled) {
+ return {
+ secretBlindIndexEnabled: false as const,
+ groups: [] as { secrets: { key: string; environment: string; secretPath: string }[] }[]
+ };
+ }
+
return withCache({
keyStore,
key: cacheKey,
ttlSeconds: KeyStoreTtls.InsightsDuplicationCacheInSeconds,
fetcher: async () => {
- const project = await projectDAL.findById(dto.projectId);
-
- if (!project.secretBlindIndexEnabled) {
- return {
- secretBlindIndexEnabled: false as const,
- groups: [] as { secrets: { key: string; environment: string; secretPath: string }[] }[]
- };
- }
const rawGroups = await secretV2BridgeDAL.findDuplicatedSecretValues(dto.projectId, {
offset: dto.offset ?? 0,
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index c5301b0bd5..c526feace9 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -1301,6 +1301,7 @@ export const registerRoutes = async (
const projectQueueService = projectQueueFactory({
queueService,
+ keyStore,
secretDAL,
secretV2BridgeDAL,
kmsService,
diff --git a/backend/src/services/project/project-queue.ts b/backend/src/services/project/project-queue.ts
index 0cc1def0d7..1c6d85e3f3 100644
--- a/backend/src/services/project/project-queue.ts
+++ b/backend/src/services/project/project-queue.ts
@@ -31,6 +31,8 @@ import { crypto } from "@app/lib/crypto/cryptography";
import { logger } from "@app/lib/logger";
import { QueueJobs, QueueName, TQueueJobTypes, TQueueServiceFactory } from "@app/queue";
+import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";
+
import { TIntegrationAuthDALFactory } from "../integration-auth/integration-auth-dal";
import { TKmsServiceFactory } from "../kms/kms-service";
import { KmsDataKey } from "../kms/kms-types";
@@ -53,6 +55,7 @@ export type TProjectQueueFactory = ReturnType<typeof projectQueueFactory>;
type TProjectQueueFactoryDep = {
queueService: TQueueServiceFactory;
+ keyStore: Pick<TKeyStoreFactory, "deleteItems">;
secretVersionDAL: Pick<TSecretVersionDALFactory, "find" | "bulkUpdateNoVersionIncrement" | "delete">;
folderDAL: Pick<TSecretFolderDALFactory, "find">;
secretDAL: Pick<TSecretDALFactory, "find" | "bulkUpdateNoVersionIncrement">;
@@ -74,6 +77,7 @@ type TProjectQueueFactoryDep = {
export const projectQueueFactory = ({
queueService,
+ keyStore,
secretDAL,
secretV2BridgeDAL,
kmsService,
@@ -725,6 +729,10 @@ export const projectQueueFactory = ({
await projectDAL.updateById(projectId, { secretBlindIndexEnabled: true });
+ await keyStore.deleteItems({
+ pattern: `${KeyStorePrefixes.InsightsCache(projectId, "secrets-duplication")}*`
+ });
+
logger.info(
`SecretBlindIndexMigration: migration complete [projectId=${projectId}] [totalProcessed=${totalProcessed}]`
);
diff --git a/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx b/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx
index 7fa89742d5..e0dffb4a06 100644
--- a/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx
+++ b/frontend/src/pages/secret-manager/InsightsPage/components/DuplicatedSecretsCard.tsx
@@ -96,10 +96,15 @@ export const DuplicatedSecretsCard = () => {
queryClient.invalidateQueries({
queryKey: secretInsightsKeys.secretsDuplication({ projectId })
});
- setMigrationTriggered(false);
}
}, [statusData?.status, migrationTriggered, projectId, queryClient]);
+ useEffect(() => {
+ if (migrationTriggered && secretBlindIndexEnabled) {
+ setMigrationTriggered(false);
+ }
+ }, [migrationTriggered, secretBlindIndexEnabled]);
+
const handleEnableClick = () => {
setMigrationTriggered(true);
enableBlindIndex.mutate(
@@ -129,8 +134,7 @@ export const DuplicatedSecretsCard = () => {
);
};
- const isMigrationRunning =
- migrationTriggered && migrationStatus !== "completed" && migrationStatus !== "failed";
+ const isMigrationRunning = migrationTriggered && migrationStatus !== "failed";
const isMigrationFailed = migrationStatus === "failed" && !enableBlindIndex.isPending;
const showEnableButton = !secretBlindIndexEnabled && !isMigrationRunning && !isMigrationFailed;