-
Notifications
You must be signed in to change notification settings - Fork 10
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
Cursor refactor #1165
Cursor refactor #1165
Conversation
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.
Looks awesome, 10/10, A+++++++, would review again
publicapi/pagination.go
Outdated
|
||
func (curs) NewBoolBoolIntIDCursorer(f func(any) (bool, bool, int64, persist.DBID, error)) cursorable { | ||
return func(node any) (c cursorer, err error) { | ||
var cur boolBootIntIDCursor |
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.
Small (but amusing) typo: boolBoot
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.
haha how did I not see that
publicapi/pagination.go
Outdated
|
||
//------------------------------------------------------------------------------ | ||
|
||
func pack(vals ...any) (string, error) { |
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 love this approach to packing cursors. Thinking out loud: assuming we passed in pointers, could an unpack
function work similarly? E.g.
func (c intTimeIDCursor) Pack() (string, error) { return pack(c.Int, c.Time, c.ID) }
func (c *intTimeIDCursor) Unpack(s string) error { return unpack(s, &c.Int, &c.Time, &c.ID) }
Cause if that worked -- potentially with some multi-error wrapper as necessary -- it would really streamline cursor definitions even more.
This PR factors out cursor logic from the paginators and adds a cursor interface that cursor types can implement:
This should pave the path for comparing cursors and faster cursor searches. At the moment, cursor equality is handled by comparing the cursor strings instead of the structs themselves. Most cursors do support this besides the more complex cursors that contain slices since go doesn't support slice comparisons out of the box. I figure I can save this for when we implement sorting + binary search.