Repository navigation
fix: group SearchDependencies CTEs by ecosystem - #250
Conversation
andrew
left a comment
There was a problem hiding this comment.
Fix is correct — verified against the #241 repro, pypi requests now reports first_seen: 2021-01-01 instead of inheriting the npm date.
Could you add a regression test before merge? internal/database/database_test.go already has the setup helpers (see TestMultipleVersionsSamePackage), and the issue has a precise repro: two ecosystems, same package name, different commit dates, then assert SearchDependencies returns the correct FirstSeen/LastChanged per ecosystem. Without one this can regress silently next time someone touches the CTE.
(Unrelated to this PR but adjacent: MIN(c.sha) as added_in in the same CTE returns the lexicographically smallest SHA rather than the SHA of the earliest commit. Pre-existing, not blocking here — happy to track separately.)
…iest commit SHA
|
Done! Added two regression tests and also fixed the added_in SHA issue you flagged:
|
andrew
left a comment
There was a problem hiding this comment.
Thanks for the tests and the bonus added_in fix.
Verified both TestSearchDependenciesCrossEcosystem and TestSearchDependenciesAddedInSHA fail on main and pass here, so they're real regression guards. Arg ordering with the extra ? is correct, and the correlated subquery hits idx_dependency_changes_name/ecosystem so it stays bounded per group.
One note for a possible follow-up (not blocking): SQLite guarantees that bare columns alongside a single MIN()/MAX() come from the row that produced the aggregate, so first_added could be SELECT dc.name, dc.ecosystem, MIN(c.committed_at) AS first_seen, c.sha AS added_in ... GROUP BY dc.name, dc.ecosystem without the subquery. We're SQLite-only via modernc so it's safe to rely on, but the explicit subquery is also fine and arguably clearer to read.
Description
This PR fixes a bug in
git pkgs searchwhere metadata (first_seen,last_changedandadded_in) could cross ecosystems for packages that share the same name (e.g.,requestsin PyPI vs npm).Previously, the
first_addedandlast_changedCommon Table Expressions (CTEs) within theSearchDependenciesmethod were only grouping and joining by the dependencyname. This update ensures they group by bothnameandecosystemto keep metadata strictly isolated to its respective ecosystem.Fixes #241
Changes Made
first_addedCTE ininternal/database/queries.goto includedc.ecosystemin theSELECTandGROUP BYclauses.last_changedCTE to also select and group bydc.ecosystem.LEFT JOINconditions to match on bothnameandecosystem.