ossf / criticality_score

Gives criticality score for an open source project
Apache License 2.0
1.32k stars 119 forks source link

Fix a memory leak by removing batch query reflection. #547

Closed calebbrown closed 8 months ago

calebbrown commented 8 months ago

This change fixes a memory leak in the implementation of BatchQuery.

Prior to this change the use of reflection dynamically created new types using reflect.StructOf. The reflect library stores an internal cache of types it has created, which eventually leaks memory.

This change fixes the issue by replacing the reflection based query, with a raw string based generated query.

To do this we removed the stale "github.com/shurcooL/githubv4" package as a dependency. And added "github.com/hasura/go-graphql-client" which is a maintained GraphQL repository that allows for raw queriws to the GraphQL API (this package is a fork of github.com/shurcooL/graphql)

This implementation introduces a Reset() method to the PagedQuery interface, as this new implementation doesn't like seeing a populated object when subsequent queries are made.