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

Enable pagination for search api #66

Merged
merged 4 commits into from
Sep 26, 2023
Merged

Enable pagination for search api #66

merged 4 commits into from
Sep 26, 2023

Conversation

dfarr
Copy link
Member

@dfarr dfarr commented Sep 22, 2023

Adds an auto incremented column named sort_id to our promises table. The search query sorts results by this column.

The SearchPromises coroutine resolves the request with a cursor containing the request to get the next page. All parameters are set to the same value as the initial request with the exception of SortId (initially nil) which is set to the last seen id.

&types.Response{
	Kind: types.SearchPromises,
	SearchPromises: &types.SearchPromisesResponse{
		Status:   types.ResponseOK,
		Promises: result.promises,
		Cursor: &types.Cursor[types.SearchPromisesRequest]{
			Next: &types.SearchPromisesRequest{
				Q:      req.SearchPromises.Q,
				T:      req.SearchPromises.T,
				States: req.SearchPromises.States,
				Limit:  req.SearchPromises.Limit,
				SortId: &result.LastSortId,
			},
		},
	},
}

The Cursor struct implements custom json marshaling logic to serialize this structure as a JWT token, this way when we get the cursor back in subsequent requests we can verify the cursor has not been tampered with.

type Cursor[T any] struct {
	Next *T
}

func (c *Cursor[T]) MarshalJSON() ([]byte, error) {
	// returns a serialized JWT token containing the next request T in the claims
}

func (c *Cursor[T]) UnmarshalJSON(data []byte) error {
	// deserializes and verifies a JWT token, sets the next request T to the value from the claims
}

Check out the implementation here.

@codecov
Copy link

codecov bot commented Sep 22, 2023

Codecov Report

Merging #66 (f164256) into main (2c7daa9) will increase coverage by 5.13%.
The diff coverage is 83.49%.

@@            Coverage Diff             @@
##             main      #66      +/-   ##
==========================================
+ Coverage   68.29%   73.43%   +5.13%     
==========================================
  Files          41       42       +1     
  Lines        4227     4288      +61     
==========================================
+ Hits         2887     3149     +262     
+ Misses       1143      941     -202     
- Partials      197      198       +1     
Files Coverage Δ
internal/app/coroutines/timeoutPromises.go 89.28% <100.00%> (ø)
...rnal/app/subsystems/aio/store/postgres/postgres.go 68.58% <100.00%> (+7.26%) ⬆️
internal/app/subsystems/aio/store/sqlite/sqlite.go 71.60% <100.00%> (+7.27%) ⬆️
internal/app/subsystems/aio/store/test/util.go 75.75% <ø> (-6.07%) ⬇️
internal/kernel/scheduler/coroutine.go 100.00% <100.00%> (ø)
internal/kernel/scheduler/scheduler.go 94.87% <100.00%> (-0.13%) ⬇️
internal/kernel/types/api_request.go 96.96% <100.00%> (+7.90%) ⬆️
internal/kernel/types/api_response.go 79.22% <ø> (+7.79%) ⬆️
pkg/promise/record.go 67.85% <100.00%> (+0.58%) ⬆️
test/dst/generator.go 100.00% <100.00%> (+4.69%) ⬆️
... and 19 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@dfarr
Copy link
Member Author

dfarr commented Sep 22, 2023

Closes #8

@dfarr dfarr changed the title Enable pagination for search api (sqlite only for now) Enable pagination for search api Sep 23, 2023
@dfarr dfarr merged commit 625bfad into main Sep 26, 2023
4 checks passed
@dfarr dfarr deleted the feature/pagination branch September 26, 2023 19:19
@dfarr dfarr mentioned this pull request Sep 28, 2023
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.

1 participant