-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paginated datastore API #1265
Paginated datastore API #1265
Conversation
aa6ec4c
to
8edefc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! 💯 I mostly pointed out missing tests, and the opportunity to create a new RelationshipIterator
that abstracts pagination, when pagination is not exposed to API client (e.g. streaming APIs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want to add unit tests for both modes of TupleOrder
and for After
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are datastore tests for both modes of TupleOrder
in the pagination.go
test suite. Does that work, or are you thinking about something else?
internal/datastore/memdb/readonly.go
Outdated
@@ -345,16 +345,99 @@ func filterFuncForFilters( | |||
return !found | |||
} | |||
|
|||
tpl := &core.RelationTuple{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is memdb and all but I wonder if we can do avoid this allocation, specially if this method is to be applied over a potentially long list of tuples. Could we perhaps take the raw relationship?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
friendly ping ☝🏻 can we make this non-allocating?
7bdf590
to
f9be65f
Compare
2e9e0a7
to
f96b17b
Compare
ResourceType: tc.objectType, | ||
}, options.WithLimit(&testLimit), options.WithAfter(&core.RelationTuple{})) | ||
require.ErrorIs(err, datastore.ErrCursorsWithoutSorting) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be a good place to also test the new paginatedIterator
given it has no tests, to make sure it properly does resuming based on batchSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think of the paginated iterator as a helper written from the perspective of the datastore consumer. As such I don't think tests for it belong here. Ideally it would test using mocks. Let me see how long it will take to write that.
internal/datastore/memdb/readonly.go
Outdated
@@ -345,16 +345,99 @@ func filterFuncForFilters( | |||
return !found | |||
} | |||
|
|||
tpl := &core.RelationTuple{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
friendly ping ☝🏻 can we make this non-allocating?
|
||
// NewPaginatedIterator creates an implementation of the datastore.Iterator | ||
// interface that internally paginates over datastore results. | ||
func NewPaginatedIterator( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not have a test, but perhaps as I proposed in pkg/datastore/test/pagination.go
, we could do integration test for the iterator there
t.Run("TestOrdering", func(t *testing.T) { OrderingTest(t, tester) }) | ||
t.Run("TestLimit", func(t *testing.T) { LimitTest(t, tester) }) | ||
t.Run("TestOrderedLimit", func(t *testing.T) { OrderedLimitTest(t, tester) }) | ||
t.Run("TestResume", func(t *testing.T) { ResumeTest(t, tester) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to be specific here: TestOrderedQueryRels
, TestResumeQueryRels
, etc
@@ -77,18 +95,120 @@ func NewSchemaQueryFilterer(schema SchemaInformation, initialQuery sq.SelectBuil | |||
} | |||
} | |||
|
|||
func (sqf SchemaQueryFilterer) TupleOrder(order options.SortOrder) SchemaQueryFilterer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add SQL tests for this (and below)
f96b17b
to
2488aca
Compare
7466b6f
to
7f1e5d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.