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
improvement: address review feedback
Scott Wilson62e63e072972
diff --git a/backend/src/ee/services/pit/pit-service.ts b/backend/src/ee/services/pit/pit-service.tsindex 3694c372b2..c89c4fef63 100644--- a/backend/src/ee/services/pit/pit-service.ts+++ b/backend/src/ee/services/pit/pit-service.ts@@ -143,10 +143,10 @@ export const pitServiceFactory = ({});return {- commits: result.commits.map(({ changes, ...commit }) => ({+ commits: result.commits.map(({ changeCounts, ...commit }) => ({...commit,commitId: commit.commitId.toString(),- summary: summarizeCommitChanges(changes)+ summary: summarizeCommitChanges(changeCounts)})),total: result.total,hasMore: result.hasMorediff --git a/backend/src/services/folder-commit/folder-commit-dal.ts b/backend/src/services/folder-commit/folder-commit-dal.tsindex 0d8ec76452..c4ac2972de 100644--- a/backend/src/services/folder-commit/folder-commit-dal.ts+++ b/backend/src/services/folder-commit/folder-commit-dal.ts@@ -15,6 +15,14 @@ import { buildFindFilter, ormify, selectAllTableCols } from "@app/lib/knex";export type TFolderCommitDALFactory = ReturnType<typeof folderCommitDALFactory>;+export type TFolderCommitChangeCount = {+ changeType: string;+ isUpdate: boolean;+ secretCount: number;+ folderCount: number;+ totalCount: number;+};+export const folderCommitDALFactory = (db: TDbClient) => {const folderCommitOrm = ormify(db, TableName.FolderCommit);const { delete: deleteOp, deleteById, ...restOfOrm } = folderCommitOrm;@@ -419,7 +427,7 @@ export const folderCommitDALFactory = (db: TDbClient) => {} = {},tx?: Knex): Promise<{- commits: (TFolderCommits & { changes: TFolderCommitChanges[] })[];+ commits: (TFolderCommits & { changeCounts: TFolderCommitChangeCount[] })[];total: number;hasMore: boolean;}> => {@@ -497,31 +505,49 @@ export const folderCommitDALFactory = (db: TDbClient) => {return { commits: [], total, hasMore: false };}- // Get all commit IDs for changesconst commitIds = folderCommits.map((commit) => commit.id);- // Get all related changes- const changes = await trx(TableName.FolderCommitChanges).whereIn("folderCommitId", commitIds).select("*");-- const changesMap = changes.reduce(- (acc, change) => {- const { folderCommitId } = change;- if (!acc[folderCommitId]) acc[folderCommitId] = [];- acc[folderCommitId].push(change);+ // Counted in the database rather than by loading the rows: a single commit can carry+ // tens of thousands of changes (a bulk import, a folder delete), and the caller only+ // needs the totals. Grouping caps this at one row per change kind per commit.+ const countRows = await trx(TableName.FolderCommitChanges)+ .whereIn("folderCommitId", commitIds)+ .groupBy("folderCommitId", "changeType", "isUpdate")+ .select<+ {+ folderCommitId: string;+ changeType: string;+ isUpdate: boolean;+ secretCount: string;+ folderCount: string;+ totalCount: string;+ }[]+ >("folderCommitId", "changeType", "isUpdate", trx.raw(`COUNT(*) FILTER (WHERE "secretVersionId" IS NOT NULL) AS "secretCount"`), trx.raw(`COUNT(*) FILTER (WHERE "folderVersionId" IS NOT NULL) AS "folderCount"`), trx.raw(`COUNT(*) AS "totalCount"`));++ const countsMap = countRows.reduce(+ (acc, row) => {+ if (!acc[row.folderCommitId]) acc[row.folderCommitId] = [];+ acc[row.folderCommitId].push({+ changeType: row.changeType,+ isUpdate: row.isUpdate,+ secretCount: Number(row.secretCount),+ folderCount: Number(row.folderCount),+ totalCount: Number(row.totalCount)+ });return acc;},- {} as Record<string, TFolderCommitChanges[]>+ {} as Record<string, TFolderCommitChangeCount[]>);- const commitsWithChanges = folderCommits.map((commit) => ({+ const commitsWithCounts = folderCommits.map((commit) => ({...commit,- changes: changesMap[commit.id] || []+ changeCounts: countsMap[commit.id] || []}));const hasMore = offset + limit < total;return {- commits: commitsWithChanges,+ commits: commitsWithCounts,total,hasMore};diff --git a/backend/src/services/folder-commit/folder-commit-fns.ts b/backend/src/services/folder-commit/folder-commit-fns.tsindex da38e63e87..3805de3980 100644--- a/backend/src/services/folder-commit/folder-commit-fns.ts+++ b/backend/src/services/folder-commit/folder-commit-fns.ts@@ -1,5 +1,4 @@-import { TFolderCommitChanges } from "@app/db/schemas";-+import { TFolderCommitChangeCount } from "./folder-commit-dal";import { CommitType } from "./folder-commit-service";export type TFolderCommitChangeSummary = {@@ -10,7 +9,7 @@ export type TFolderCommitChangeSummary = {deletedCount: number;};-export const summarizeCommitChanges = (changes: TFolderCommitChanges[]): TFolderCommitChangeSummary => {+export const summarizeCommitChanges = (changeCounts: TFolderCommitChangeCount[]): TFolderCommitChangeSummary => {const summary: TFolderCommitChangeSummary = {secretCount: 0,folderCount: 0,@@ -19,16 +18,16 @@ export const summarizeCommitChanges = (changes: TFolderCommitChanges[]): TFolderdeletedCount: 0};- for (const change of changes) {- if (change.secretVersionId) summary.secretCount += 1;- if (change.folderVersionId) summary.folderCount += 1;+ for (const count of changeCounts) {+ summary.secretCount += count.secretCount;+ summary.folderCount += count.folderCount;- if (change.changeType === CommitType.DELETE) {- summary.deletedCount += 1;- } else if (change.isUpdate) {- summary.updatedCount += 1;+ if (count.changeType === CommitType.DELETE) {+ summary.deletedCount += count.totalCount;+ } else if (count.isUpdate) {+ summary.updatedCount += count.totalCount;} else {- summary.addedCount += 1;+ summary.addedCount += count.totalCount;}}diff --git a/frontend/src/components/secrets/CommitHistorySheet/CommitDetailsView.tsx b/frontend/src/components/secrets/CommitHistorySheet/CommitDetailsView.tsxindex 568cdc8fa8..acddfa1a4f 100644--- a/frontend/src/components/secrets/CommitHistorySheet/CommitDetailsView.tsx+++ b/frontend/src/components/secrets/CommitHistorySheet/CommitDetailsView.tsx@@ -1,11 +1,13 @@import { useEffect, useState } from "react";+import axios from "axios";import { format } from "date-fns";import {ChevronDownIcon,GitCommitHorizontalIcon,InfoIcon,MaximizeIcon,- MinimizeIcon+ MinimizeIcon,+ TriangleAlertIcon} from "lucide-react";import { createNotification } from "@app/components/notifications";@@ -27,6 +29,8 @@ import {DropdownMenuItem,DropdownMenuTrigger,Empty,+ EmptyContent,+ EmptyDescription,EmptyHeader,EmptyMedia,EmptyTitle,@@ -81,7 +85,12 @@ export const CommitDetailsView = ({const [isRevertOpen, setIsRevertOpen] = useState(false);const [revertConfirmation, setRevertConfirmation] = useState("");- const { data: commitDetails, isPending } = useGetCommitDetails(projectId, commitId);+ const {+ data: commitDetails,+ isPending,+ error,+ refetch+ } = useGetCommitDetails(projectId, commitId);const { mutateAsync: revert, isPending: isReverting } = useCommitRevert({commitId,projectId,@@ -122,6 +131,10 @@ export const CommitDetailsView = ({}if (!commit) {+ // A commit reachable from the history list only 404s if it was pruned since the list+ // loaded, so anything else is an operational failure the user can retry out of+ const isMissing = axios.isAxiosError(error) && error.response?.status === 404;+return (<><SheetHeader>@@ -132,10 +145,22 @@ export const CommitDetailsView = ({<Empty><EmptyHeader><EmptyMedia variant="icon">- <GitCommitHorizontalIcon />+ {isMissing ? <GitCommitHorizontalIcon /> : <TriangleAlertIcon />}</EmptyMedia>- <EmptyTitle>Commit Not Found</EmptyTitle>+ <EmptyTitle>{isMissing ? "Commit Not Found" : "Unable To Load Commit"}</EmptyTitle>+ <EmptyDescription>+ {isMissing+ ? "This commit is no longer part of this folder's history."+ : "Something went wrong loading the changes in this commit."}+ </EmptyDescription></EmptyHeader>+ {!isMissing && (+ <EmptyContent>+ <Button variant="outline" size="sm" onClick={() => refetch()}>+ Try Again+ </Button>+ </EmptyContent>+ )}</Empty></div></>diff --git a/frontend/src/components/secrets/CommitHistorySheet/CommitHistorySheet.tsx b/frontend/src/components/secrets/CommitHistorySheet/CommitHistorySheet.tsxindex ecc331ace2..cf7968a964 100644--- a/frontend/src/components/secrets/CommitHistorySheet/CommitHistorySheet.tsx+++ b/frontend/src/components/secrets/CommitHistorySheet/CommitHistorySheet.tsx@@ -1,7 +1,6 @@import { useEffect, useState } from "react";import { Sheet, SheetContent } from "@app/components/v3";-import { useGetFolderCommitsCount } from "@app/hooks/api/folderCommits/queries";import { CommitDetailsView } from "./CommitDetailsView";import { CommitHistoryView } from "./CommitHistoryView";@@ -9,8 +8,8 @@ import { CommitRestoreView } from "./CommitRestoreView";type View =| { name: "history" }- | { name: "details"; commitId: string }- | { name: "restore"; commitId: string };+ | { name: "details"; commitId: string; folderId: string }+ | { name: "restore"; commitId: string; folderId: string };type Props = {isOpen: boolean;@@ -33,14 +32,6 @@ export const CommitHistorySheet = ({}: Props) => {const [view, setView] = useState<View>({ name: "history" });- const { data: commitsCount } = useGetFolderCommitsCount({- projectId,- environment,- directory: secretPath,- isPaused: !isOpen- });- const folderId = commitsCount?.folderId;-// Reopening on a different environment or path must not inherit the previous scope's viewuseEffect(() => {if (isOpen) setView({ name: "history" });@@ -55,7 +46,9 @@ export const CommitHistorySheet = ({environment={environment}environmentName={environmentName}secretPath={secretPath}- onSelectCommit={(commitId) => setView({ name: "details", commitId })}+ onSelectCommit={(commitId, folderId) =>+ setView({ name: "details", commitId, folderId })+ }/>)}@@ -68,18 +61,22 @@ export const CommitHistorySheet = ({commitId={view.commitId}onBack={() => setView({ name: "history" })}onCommitReverted={() => setView({ name: "history" })}- onGoToRestore={() => setView({ name: "restore", commitId: view.commitId })}+ onGoToRestore={() =>+ setView({ name: "restore", commitId: view.commitId, folderId: view.folderId })+ }/>)}- {view.name === "restore" && folderId && (+ {view.name === "restore" && (<CommitRestoreViewprojectId={projectId}environment={environment}secretPath={secretPath}- folderId={folderId}+ folderId={view.folderId}commitId={view.commitId}- onBack={() => setView({ name: "details", commitId: view.commitId })}+ onBack={() =>+ setView({ name: "details", commitId: view.commitId, folderId: view.folderId })+ }onRestored={() => setView({ name: "history" })}/>)}diff --git a/frontend/src/components/secrets/CommitHistorySheet/CommitHistoryView.tsx b/frontend/src/components/secrets/CommitHistorySheet/CommitHistoryView.tsxindex 8bec6e39b8..1c2adec252 100644--- a/frontend/src/components/secrets/CommitHistorySheet/CommitHistoryView.tsx+++ b/frontend/src/components/secrets/CommitHistorySheet/CommitHistoryView.tsx@@ -7,7 +7,8 @@ import {ChevronRightIcon,GitCommitHorizontalIcon,InfoIcon,- SearchIcon+ SearchIcon,+ TriangleAlertIcon} from "lucide-react";import {@@ -18,6 +19,7 @@ import {DropdownMenuItem,DropdownMenuTrigger,Empty,+ EmptyContent,EmptyDescription,EmptyHeader,EmptyMedia,@@ -116,7 +118,7 @@ type Props = {environment: string;environmentName: string;secretPath: string;- onSelectCommit: (commitId: string) => void;+ onSelectCommit: (commitId: string, folderId: string) => void;};export const CommitHistoryView = ({@@ -133,7 +135,7 @@ export const CommitHistoryView = ({const { data: authors } = useGetCommitAuthors({ projectId, environment, directory: secretPath });- const { data, isPending, fetchNextPage, isFetchingNextPage, hasNextPage } =+ const { data, isPending, isError, refetch, fetchNextPage, isFetchingNextPage, hasNextPage } =useGetFolderCommitHistory({projectId,environment,@@ -149,6 +151,7 @@ export const CommitHistoryView = ({);const remainingCount = (data?.total ?? 0) - (data?.loadedCount ?? 0);const isFiltered = Boolean(debouncedSearch || author);+ const hasCommits = Boolean(data?.groups.length);return (<>@@ -237,7 +240,26 @@ export const CommitHistoryView = ({>{isPending && <CommitHistorySkeleton />}- {!isPending && !data?.groups.length && (+ {!isPending && !hasCommits && isError && (+ <Empty className="h-full">+ <EmptyHeader>+ <EmptyMedia variant="icon">+ <TriangleAlertIcon />+ </EmptyMedia>+ <EmptyTitle>Unable To Load Commit History</EmptyTitle>+ <EmptyDescription>+ Something went wrong loading the commits for this path.+ </EmptyDescription>+ </EmptyHeader>+ <EmptyContent>+ <Button variant="outline" size="sm" onClick={() => refetch()}>+ Try Again+ </Button>+ </EmptyContent>+ </Empty>+ )}++ {!isPending && !hasCommits && !isError && (<Empty className="h-full"><EmptyHeader><EmptyMedia variant="icon">@@ -253,9 +275,9 @@ export const CommitHistoryView = ({</Empty>)}- {!isPending && !!data?.groups.length && (+ {!isPending && hasCommits && (<div>- {data.groups.map((group) => (+ {data?.groups.map((group) => (<div key={group.date} className="mb-6 last:mb-0"><div className="mb-2 flex items-center gap-2"><GitCommitHorizontalIcon className="size-4 text-muted" />@@ -274,7 +296,7 @@ export const CommitHistoryView = ({<CommitRowkey={commit.id}commit={commit}- onSelect={() => onSelectCommit(commit.id)}+ onSelect={() => onSelectCommit(commit.id, commit.folderId)}/>))}</div>diff --git a/frontend/src/hooks/api/folderCommits/types.ts b/frontend/src/hooks/api/folderCommits/types.tsindex 1c23fee70d..3003d3ad20 100644--- a/frontend/src/hooks/api/folderCommits/types.ts+++ b/frontend/src/hooks/api/folderCommits/types.ts@@ -79,6 +79,7 @@ export type CommitChangeSummary = {export interface Commit {id: string;+ folderId: string;message?: string | null;createdAt: string;actorType: string;