Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refactor(insights): simplify cache key generation for access volume and auth methods
DimitrisStaratzis4961110cabee
diff --git a/backend/src/ee/services/insights/insights-service.test.ts b/backend/src/ee/services/insights/insights-service.test.tsindex 0c2f2a2604..acae7bee45 100644--- a/backend/src/ee/services/insights/insights-service.test.ts+++ b/backend/src/ee/services/insights/insights-service.test.ts@@ -232,7 +232,6 @@ describe("project access insights audit log store", () => {} as OrgServiceActor;const buildProjectService = ({ withClickHouse }: { withClickHouse: boolean }) => {- const cachedKeys: string[] = [];const postgres = {countByDateAndActor: vi.fn(async () => []),countByAuthMethod: vi.fn(async () => [])@@ -272,12 +271,9 @@ describe("project access insights audit log store", () => {} as TInsightsServiceFactoryDep["licenseService"],keyStore: {getItem: async () => null,- setItemWithExpiry: async (key: string) => {- cachedKeys.push(key);- return "OK";- },+ setItemWithExpiry: async () => "OK",ttl: async () => -2- } as unknown as TInsightsServiceFactoryDep["keyStore"],+ },orgDAL: {countSecretManagerProjectMembers: unreachable("orgDAL.countSecretManagerProjectMembers"),findById: unreachable("orgDAL.findById")@@ -295,7 +291,7 @@ describe("project access insights audit log store", () => {}});- return { service, postgres, clickhouse, cachedKeys };+ return { service, postgres, clickhouse };};beforeEach(() => {@@ -354,15 +350,4 @@ describe("project access insights audit log store", () => {{ method: "Email", count: 2 }]);});-- test("caches each store's counts under its own key", async () => {- const { service, cachedKeys } = buildProjectService({ withClickHouse: true });- await service.getAccessVolume({ projectId: PROJECT_ID }, projectActor);-- appConfig.CLICKHOUSE_AUDIT_LOG_ENABLED = true;- await service.getAccessVolume({ projectId: PROJECT_ID }, projectActor);-- expect(cachedKeys).toHaveLength(2);- expect(new Set(cachedKeys).size).toBe(2);- });});diff --git a/backend/src/ee/services/insights/insights-service.ts b/backend/src/ee/services/insights/insights-service.tsindex 4709d45f14..bcd84f17a3 100644--- a/backend/src/ee/services/insights/insights-service.ts+++ b/backend/src/ee/services/insights/insights-service.ts@@ -272,11 +272,7 @@ export const insightsServiceFactory = ({await checkInsightsPermission(permissionService, licenseService, dto.projectId, actorDto);const clickhouseDAL = $getClickHouseAuditLogDAL();- // The store is part of the key so switching it never serves counts cached from the other one.- const cacheKey = KeyStorePrefixes.InsightsCache(- dto.projectId,- `access-volume:${clickhouseDAL ? "clickhouse" : "postgres"}`- );+ const cacheKey = KeyStorePrefixes.InsightsCache(dto.projectId, "access-volume");return withCache({keyStore,key: cacheKey,@@ -334,10 +330,7 @@ export const insightsServiceFactory = ({await checkInsightsPermission(permissionService, licenseService, dto.projectId, actorDto);const clickhouseDAL = $getClickHouseAuditLogDAL();- const cacheKey = KeyStorePrefixes.InsightsCache(- dto.projectId,- `auth-methods:${dto.days}:${clickhouseDAL ? "clickhouse" : "postgres"}`- );+ const cacheKey = KeyStorePrefixes.InsightsCache(dto.projectId, `auth-methods:${dto.days}`);return withCache({keyStore,key: cacheKey,