Add narrow audit log actor loaders for CSV export
Replace full Identity and PersonalAPIKey batch loads with rows that select only id, email, name fields used in export. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
@@ -388,7 +388,17 @@ WHERE
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Identities) LoadByIDs(
|
type (
|
||||||
|
IdentityAuditLogActorRow struct {
|
||||||
|
ID gid.GID `db:"id"`
|
||||||
|
EmailAddress mail.Addr `db:"email_address"`
|
||||||
|
FullName string `db:"full_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
IdentityAuditLogActorRows []*IdentityAuditLogActorRow
|
||||||
|
)
|
||||||
|
|
||||||
|
func (rows *IdentityAuditLogActorRows) LoadByIDs(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
identityIDs []gid.GID,
|
identityIDs []gid.GID,
|
||||||
@@ -397,13 +407,7 @@ func (i *Identities) LoadByIDs(
|
|||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
email_address,
|
email_address,
|
||||||
full_name,
|
full_name
|
||||||
hashed_password,
|
|
||||||
email_address_verified,
|
|
||||||
saml_subject,
|
|
||||||
locale,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM
|
FROM
|
||||||
identities
|
identities
|
||||||
WHERE
|
WHERE
|
||||||
@@ -412,17 +416,17 @@ WHERE
|
|||||||
|
|
||||||
args := pgx.StrictNamedArgs{"identity_ids": identityIDs}
|
args := pgx.StrictNamedArgs{"identity_ids": identityIDs}
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rowsResult, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query identities: %w", err)
|
return fmt.Errorf("cannot query identity audit log actors: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
identities, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[Identity])
|
actors, err := pgx.CollectRows(rowsResult, pgx.RowToAddrOfStructByName[IdentityAuditLogActorRow])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot collect identities: %w", err)
|
return fmt.Errorf("cannot collect identity audit log actors: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
*i = identities
|
*rows = actors
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,7 +302,16 @@ WHERE
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PersonalAPIKeys) LoadByIDs(
|
type (
|
||||||
|
PersonalAPIKeyAuditLogActorRow struct {
|
||||||
|
ID gid.GID `db:"id"`
|
||||||
|
Name string `db:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
PersonalAPIKeyAuditLogActorRows []*PersonalAPIKeyAuditLogActorRow
|
||||||
|
)
|
||||||
|
|
||||||
|
func (rows *PersonalAPIKeyAuditLogActorRows) LoadByIDs(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
apiKeyIDs []gid.GID,
|
apiKeyIDs []gid.GID,
|
||||||
@@ -310,13 +319,7 @@ func (a *PersonalAPIKeys) LoadByIDs(
|
|||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
identity_id,
|
name
|
||||||
name,
|
|
||||||
expires_at,
|
|
||||||
expire_reason,
|
|
||||||
last_used_at,
|
|
||||||
created_at,
|
|
||||||
updated_at
|
|
||||||
FROM
|
FROM
|
||||||
iam_personal_api_keys
|
iam_personal_api_keys
|
||||||
WHERE
|
WHERE
|
||||||
@@ -325,17 +328,17 @@ WHERE
|
|||||||
|
|
||||||
args := pgx.StrictNamedArgs{"api_key_ids": apiKeyIDs}
|
args := pgx.StrictNamedArgs{"api_key_ids": apiKeyIDs}
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rowsResult, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query personal api keys: %w", err)
|
return fmt.Errorf("cannot query personal api key audit log actors: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
apiKeys, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[PersonalAPIKey])
|
actors, err := pgx.CollectRows(rowsResult, pgx.RowToAddrOfStructByName[PersonalAPIKeyAuditLogActorRow])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot collect personal api keys: %w", err)
|
return fmt.Errorf("cannot collect personal api key audit log actors: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
*a = apiKeys
|
*rows = actors
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -270,8 +270,7 @@ func loadAuditLogActorExportInfo(
|
|||||||
|
|
||||||
result := make(map[gid.GID]auditLogActorExportInfo)
|
result := make(map[gid.GID]auditLogActorExportInfo)
|
||||||
|
|
||||||
if len(identityIDs) > 0 {
|
var identities coredata.IdentityAuditLogActorRows
|
||||||
var identities coredata.Identities
|
|
||||||
if err := identities.LoadByIDs(ctx, conn, identityIDs); err != nil {
|
if err := identities.LoadByIDs(ctx, conn, identityIDs); err != nil {
|
||||||
return nil, fmt.Errorf("cannot load audit log actor identities: %w", err)
|
return nil, fmt.Errorf("cannot load audit log actor identities: %w", err)
|
||||||
}
|
}
|
||||||
@@ -282,10 +281,8 @@ func loadAuditLogActorExportInfo(
|
|||||||
name: identity.FullName,
|
name: identity.FullName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if len(apiKeyIDs) > 0 {
|
var apiKeys coredata.PersonalAPIKeyAuditLogActorRows
|
||||||
var apiKeys coredata.PersonalAPIKeys
|
|
||||||
if err := apiKeys.LoadByIDs(ctx, conn, apiKeyIDs); err != nil {
|
if err := apiKeys.LoadByIDs(ctx, conn, apiKeyIDs); err != nil {
|
||||||
return nil, fmt.Errorf("cannot load audit log actor API keys: %w", err)
|
return nil, fmt.Errorf("cannot load audit log actor API keys: %w", err)
|
||||||
}
|
}
|
||||||
@@ -295,7 +292,6 @@ func loadAuditLogActorExportInfo(
|
|||||||
name: apiKey.Name,
|
name: apiKey.Name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user