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

[Pagination] add new connection resolver#45167

Merged
0xnmn merged 1 commit into
mainfrom
naman/connection-resolver
Dec 13, 2022
Merged

[Pagination] add new connection resolver#45167
0xnmn merged 1 commit into
mainfrom
naman/connection-resolver

Conversation

@0xnmn

@0xnmn 0xnmn commented Dec 5, 2022

Copy link
Copy Markdown
Contributor

Closes: https://github.com/sourcegraph/sourcegraph/issues/45247
This PR implements a new connection resolver helper, which is planned to be used to implement cursor-based bi-directional pagination throughout our software. This is the first PR which only implements the helper along with its basic unit tests.

The upcoming PRs will include its integration with SavedSearches resolver. The custom sort and filters will be added separately as well.

Test plan

Unit tests are added.

To know more about how this helper will be used, check this out.

@0xnmn 0xnmn self-assigned this Dec 5, 2022
@cla-bot cla-bot Bot added the cla-signed label Dec 5, 2022
@0xnmn 0xnmn requested review from a team, 0xPerko, mrnugget and philipp-spiess and removed request for 0xPerko December 5, 2022 13:14
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
@0xnmn 0xnmn requested a review from philipp-spiess December 5, 2022 13:40

@philipp-spiess philipp-spiess 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.

Looks great from my side! I'll leave this open for a bit so that someone with more backend experience can also look over it though (*cough* @mrnugget) 🙈

Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment on lines +69 to +97
type resolveOnce struct {
total sync.Once
nodes sync.Once
}

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.

What is the reason behind using the sync.Once library function here?

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.

when calculative pageInfo, we need to count nodes. so if in the query we are fetch both nodes and pageInfo (which is always the case) we will need to compute it twice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think these two fields need to live in a separate type, can inline where it's used.

Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread internal/database/helpers.go

@mrnugget mrnugget 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.

I did a first round of review and mostly commented on code style and quality. It's still a bit hard to judge how far this interface will go without having to be changed, especially since we don't have an example in here.

Requesting changes so that you

  • clean up the tests. There's a lot of code in there that can be removed. I bet that whole test file could be 1/4 of its size. (see the one test helper example that I commented)
  • add comments to the tests to explain what's being tested where
  • make the assertions in the tests clearer: does it matter that we pass in this function, does it not? do we assert what nodes are returned or not? for some of them you want to test the behaviour of your logic here (that the order of the nodes is reverserd, for example, but I don't see that here)
  • clean up the ConnectionResolver (change the int/int32 stuff so it's less casting, add docstrings, remove some superfluous checks, ...)

Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated

@eseliger eseliger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a bunch of nit comments here and there, nothing major. Great work :)

I would love to see this applied to one or two of our existing connections in different parts of the code base that use slightly different patterns, to validate that we can apply this broadly

Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment on lines +69 to +97
type resolveOnce struct {
total sync.Once
nodes sync.Once
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think these two fields need to live in a separate type, can inline where it's used.

Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go

@mrnugget mrnugget 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.

Tests and code looks much better! Thanks! There's still a few comments that are unanswered, so I'm waiting for those to be either answered or resolved until approval

Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go
Comment thread internal/database/helpers.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go Outdated
Comment thread cmd/frontend/graphqlbackend/graphqlutil/connection_resolver_test.go Outdated
@0xnmn 0xnmn force-pushed the naman/connection-resolver branch from e0c0fb5 to ced63f0 Compare December 13, 2022 09:24
@sourcegraph-bot

sourcegraph-bot commented Dec 13, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff e540a5a...f6f161d.

No notifications.

@0xnmn 0xnmn force-pushed the naman/connection-resolver branch from d585832 to f6f161d Compare December 13, 2022 10:42

@mrnugget mrnugget 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.

Let's go!

@0xnmn 0xnmn enabled auto-merge (squash) December 13, 2022 10:45
@philipp-spiess

philipp-spiess commented Dec 13, 2022

Copy link
Copy Markdown
Contributor

@thenamankumar Looks like auto-merge is bugged/doesn't update when main was unblocked 🙈 Want to re-trigger it? I don't want to merge on your behalf haha

Screenshot 2022-12-13 at 13 00 09

@0xnmn 0xnmn merged commit 6daa27a into main Dec 13, 2022
@0xnmn 0xnmn deleted the naman/connection-resolver branch December 13, 2022 15:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a new backend abstraction that adds bi-directional pagination support for simple routes (without supporting custom orderings, @thenamankumar )

6 participants