chore: implement sane default pagination limit for audit logs (#13676)

* chore: implement sane default pagination limit for audit logs
This commit is contained in:
Steven Masley
2024-06-28 02:38:04 -10:00
committed by GitHub
parent 1a877716ca
commit 3cc86cf62d
10 changed files with 78 additions and 45 deletions

View File

@ -1965,12 +1965,17 @@ func (q *FakeQuerier) GetAuditLogsOffset(_ context.Context, arg database.GetAudi
q.mutex.RLock()
defer q.mutex.RUnlock()
logs := make([]database.GetAuditLogsOffsetRow, 0, arg.Limit)
if arg.LimitOpt == 0 {
// Default to 100 is set in the SQL query.
arg.LimitOpt = 100
}
logs := make([]database.GetAuditLogsOffsetRow, 0, arg.LimitOpt)
// q.auditLogs are already sorted by time DESC, so no need to sort after the fact.
for _, alog := range q.auditLogs {
if arg.Offset > 0 {
arg.Offset--
if arg.OffsetOpt > 0 {
arg.OffsetOpt--
continue
}
if arg.OrganizationID != uuid.Nil && arg.OrganizationID != alog.OrganizationID {
@ -2047,7 +2052,7 @@ func (q *FakeQuerier) GetAuditLogsOffset(_ context.Context, arg database.GetAudi
Count: 0,
})
if len(logs) >= int(arg.Limit) {
if len(logs) >= int(arg.LimitOpt) {
break
}
}