Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

chore: Factor out sub-query for locating nearest uploads#64210

Merged
varungandhi-src merged 3 commits into
mainfrom
vg/factor-subquery
Aug 1, 2024
Merged

chore: Factor out sub-query for locating nearest uploads#64210
varungandhi-src merged 3 commits into
mainfrom
vg/factor-subquery

Conversation

@varungandhi-src

Copy link
Copy Markdown
Contributor

A large sub-query was duplicated between two queries, making
the code harder to understand. This patch factors that out.

Ancillary changes:

  • Added more doc comments
  • Tweak tests to make failures easier to follow.

Test plan

Covered by existing tests

@cla-bot cla-bot Bot added the cla-signed label Aug 1, 2024
@github-actions github-actions Bot added team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform labels Aug 1, 2024

@kritzcreek kritzcreek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment update and a small nit

repositoryID, dbutil.CommitBytea(commit),
repositoryID, dbutil.CommitBytea(commit),
)
// visible from the given set of commits. This is done by removing the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You say "from the given set of commits" here, but then further down "This function deliberately accepts a single commit". Which is it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this function was changed to accept a list in the middle of refactoring and then I changed it back once I realized the problem with correctness.

Comment on lines +82 to +85
func makeNearestUploadsQuery(repositoryID api.RepoID, commits ...api.CommitID) *sqlf.Query {
commitQueries := sqlf.Join(genslices.Map(commits, func(commit api.CommitID) *sqlf.Query {
return sqlf.Sprintf("%s", dbutil.CommitBytea(commit))
}), ", ")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I've found that because of the lack of inference for lambdas, it's sometimes a little easier to read genslice code when you pull out a small top-level function.

Suggested change
func makeNearestUploadsQuery(repositoryID api.RepoID, commits ...api.CommitID) *sqlf.Query {
commitQueries := sqlf.Join(genslices.Map(commits, func(commit api.CommitID) *sqlf.Query {
return sqlf.Sprintf("%s", dbutil.CommitBytea(commit))
}), ", ")
func formatCommit(commit api.CommitID) *sqlf.Query {
return sqlf.Sprintf("%s", dbutil.CommitBytea(commit))
}
func makeNearestUploadsQuery(repositoryID api.RepoID, commits ...api.CommitID) *sqlf.Query {
commitQueries := sqlf.Join(genslices.Map(commits, formatCommit), ", ")

@varungandhi-src varungandhi-src Aug 1, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this to use a local function instead of a top-level function since sometimes commits are used as text columns, so the name might be misleading if it were a top-level function.

@varungandhi-src varungandhi-src merged commit 554fd33 into main Aug 1, 2024
@varungandhi-src varungandhi-src deleted the vg/factor-subquery branch August 1, 2024 13:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed team/graph Graph Team (previously Code Intel/Language Tools/Language Platform) team/product-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants