Fix OpenProcessing visualID type mismatch causing rate limiting #959
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
related to #955
Problem
The OpenProcessing API was experiencing 429 rate limiting errors during build due to excessive API calls. Investigation revealed that sketch memoization was failing because of a type mismatch between the API response (
visualID: number
) and the comparison logic (string
).Changes
visualID
type fromstring
tonumber
toString()
calls inHomepageLayout
String(sketch.visualID)
) to prevent TypeScript from inferringAstro.params.slug
asnumber
SketchLayout
(const sketchIdNumber = Number(sketchId)
)number
parameters (previouslystring
)I considered two approaches:
OpenProcessing.ts
acceptingstring
and convert internally tonumber
sketchId
tonumber
once in theSketchLayout
and have functions acceptnumber
as parametersI went with option 2 because I thought it's more consistent with the
visualID
type and avoids multiple conversions per function call. Let me know if you think a different approach would be better.Future Work
Currently, I added basic validation for invalid sketch IDs in
SketchLayout.astro
:However, this only logs the error and continues execution, potentially passing
NaN
to OpenProcessing functions.I think A follow-up PR should address proper error handling such as:
getStaticPaths
Thanks for reviewing!