Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): Limit validation to 50k issues #3277

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { validationSeveritySort } from "../validation"

vi.mock("../../../config.ts")

describe("validation resolvers", () => {
describe("validationSeveritySort", () => {
it("sorts severity error before warning", () => {
const issues = [
{ severity: "warning" },
{ severity: "error" },
{ severity: "error" },
{ severity: "warning" },
{ severity: "error" },
]
const sortedIssues = issues.sort(validationSeveritySort)
expect(sortedIssues[0].severity).toBe("error")
expect(sortedIssues[1].severity).toBe("error")
expect(sortedIssues[2].severity).toBe("error")
expect(sortedIssues[3].severity).toBe("warning")
})
})
})
9 changes: 9 additions & 0 deletions packages/openneuro-server/src/graphql/resolvers/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@
.exec()
}

export function validationSeveritySort(a, b) {
return a.severity.localeCompare(b.severity)
}

/**
* Save issues data returned by the datalad service
*
* Returns only a boolean if successful or not
*/
export const updateValidation = (obj, args) => {
// Limit to 50k issues with errors sorted first
if (args.validation.issues.length > 50000) {
args.validation.issues.sort(validationSeveritySort)
args.validation.issues = args.validation.issues.slice(0, 50000)
}

Check warning on line 55 in packages/openneuro-server/src/graphql/resolvers/validation.ts

View check run for this annotation

Codecov / codecov/patch

packages/openneuro-server/src/graphql/resolvers/validation.ts#L51-L55

Added lines #L51 - L55 were not covered by tests
return Validation.updateOne(
{
id: args.validation.id,
Expand Down
Loading