Skip to content

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

remove pagination and check ttl after withCache call

Matheus Nogueiraf004d4087308
diff --git a/backend/src/ee/routes/v1/insights-router.ts b/backend/src/ee/routes/v1/insights-router.ts
index a9a1103ba0..86767c3304 100644
--- a/backend/src/ee/routes/v1/insights-router.ts
+++ b/backend/src/ee/routes/v1/insights-router.ts
@@ -172,9 +172,7 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
description: "Get groups of duplicated secrets across environments and paths",
security: [{ bearerAuth: [] }],
querystring: z.object({
- projectId: z.string().trim(),
- offset: z.coerce.number().min(0).max(10000).default(0),
- limit: z.coerce.number().min(1).max(100).default(50)
+ projectId: z.string().trim()
}),
response: {
200: z.object({
@@ -196,9 +194,9 @@ export const registerInsightsRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req, reply) => {
- const { projectId, offset, limit } = req.query;
+ const { projectId } = req.query;
const { result, remainingTTL } = await server.services.insights.getSecretsDuplication(
- { projectId, offset, limit },
+ { projectId },
req.permission
);
await server.services.auditLog.createAuditLog({
diff --git a/backend/src/ee/services/insights/insights-service.ts b/backend/src/ee/services/insights/insights-service.ts
index 907139142d..88b9dd951a 100644
--- a/backend/src/ee/services/insights/insights-service.ts
+++ b/backend/src/ee/services/insights/insights-service.ts
@@ -503,10 +503,7 @@ export const insightsServiceFactory = ({
const getSecretsDuplication = async (dto: TGetSecretsDuplicationDTO, actorDto: OrgServiceActor) => {
await checkInsightsPermission(permissionService, licenseService, dto.projectId, actorDto);
- const cacheKey = KeyStorePrefixes.InsightsCache(
- dto.projectId,
- `secrets-duplication:${dto.offset ?? 0}:${dto.limit ?? 50}`
- );
+ const cacheKey = KeyStorePrefixes.InsightsCache(dto.projectId, "secrets-duplication");
const project = await projectDAL.findById(dto.projectId);
@@ -522,17 +519,12 @@ export const insightsServiceFactory = ({
};
}
- const remainingTTL = await getCacheTtl(keyStore, cacheKey);
-
const result = await withCache({
keyStore,
key: cacheKey,
ttlSeconds: KeyStoreTtls.InsightsDuplicationCacheInSeconds,
fetcher: async () => {
- const rawGroups = await secretV2BridgeDAL.findDuplicatedSecretValues(dto.projectId, {
- offset: dto.offset ?? 0,
- limit: dto.limit ?? 50
- });
+ const rawGroups = await secretV2BridgeDAL.findDuplicatedSecretValues(dto.projectId);
const { decryptor: secretManagerDecryptor } = await kmsService.createCipherPairWithDataKey({
type: KmsDataKey.SecretManager,
@@ -569,6 +561,8 @@ export const insightsServiceFactory = ({
}
});
+ const remainingTTL = await getCacheTtl(keyStore, cacheKey);
+
return { result, remainingTTL };
};
diff --git a/backend/src/ee/services/insights/insights-types.ts b/backend/src/ee/services/insights/insights-types.ts
index ae9bb70268..787e335372 100644
--- a/backend/src/ee/services/insights/insights-types.ts
+++ b/backend/src/ee/services/insights/insights-types.ts
@@ -26,6 +26,4 @@ export type TGetInsightsSummaryDTO = {
export type TGetSecretsDuplicationDTO = {
projectId: string;
- offset?: number;
- limit?: number;
};
diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
index be6b12a252..01037833db 100644
--- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
+++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-dal.ts
@@ -1241,11 +1241,7 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
}
};
- const findDuplicatedSecretValues = async (
- projectId: string,
- pagination?: { offset: number; limit: number },
- tx?: Knex
- ) => {
+ const findDuplicatedSecretValues = async (projectId: string, tx?: Knex) => {
try {
const duplicateBlindIndexes = (tx || db.replicaNode())(TableName.SecretV2)
.join(TableName.SecretFolder, `${TableName.SecretV2}.folderId`, `${TableName.SecretFolder}.id`)
@@ -1257,9 +1253,7 @@ export const secretV2BridgeDALFactory = ({ db, keyStore }: TSecretV2DalArg) => {
.groupBy(`${TableName.SecretV2}.secretValueBlindIndex`)
.having(db.raw("count(*) > 1"))
.select(`${TableName.SecretV2}.secretValueBlindIndex`)
- .orderBy(`${TableName.SecretV2}.secretValueBlindIndex`)
- .offset(pagination?.offset ?? 0)
- .limit(pagination?.limit ?? 50);
+ .orderBy(`${TableName.SecretV2}.secretValueBlindIndex`);
const rows = await (tx || db.replicaNode())(TableName.SecretV2)
.join(TableName.SecretFolder, `${TableName.SecretV2}.folderId`, `${TableName.SecretFolder}.id`)
diff --git a/frontend/src/hooks/api/secretInsights/types.ts b/frontend/src/hooks/api/secretInsights/types.ts
index eca15db325..f78c657760 100644
--- a/frontend/src/hooks/api/secretInsights/types.ts
+++ b/frontend/src/hooks/api/secretInsights/types.ts
@@ -123,8 +123,6 @@ export type TGetAuthMethodDistributionResponse = {
export type TGetSecretsDuplicationDTO = {
projectId: string;
- offset?: number;
- limit?: number;
};
export type TDuplicatedSecretEntry = {