Skip to content
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

Merged
merged 7 commits into from
Aug 29, 2023
Merged

Cursor refactor #1165

merged 7 commits into from
Aug 29, 2023

Conversation

jarrel-b
Copy link
Collaborator

This PR factors out cursor logic from the paginators and adds a cursor interface that cursor types can implement:

type cursorer interface {
	Pack() (string, error) // Encodes the cursor as a string
	Unpack(string) error // Decodes the cursor into the receiver
}

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.

Copy link
Contributor

@radazen radazen left a 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


func (curs) NewBoolBoolIntIDCursorer(f func(any) (bool, bool, int64, persist.DBID, error)) cursorable {
return func(node any) (c cursorer, err error) {
var cur boolBootIntIDCursor
Copy link
Contributor

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

Copy link
Collaborator Author

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


//------------------------------------------------------------------------------

func pack(vals ...any) (string, error) {
Copy link
Contributor

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.

@jarrel-b jarrel-b merged commit 3f7db2a into main Aug 29, 2023
5 checks passed
@jarrel-b jarrel-b deleted the jarrel/cursors branch August 29, 2023 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants