refactor(query): add QueryDatastoreReader to act as an implementation shim for datastores#2956
refactor(query): add QueryDatastoreReader to act as an implementation shim for datastores#2956
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2956 +/- ##
==========================================
+ Coverage 74.84% 74.85% +0.01%
==========================================
Files 496 498 +2
Lines 60695 60746 +51
==========================================
+ Hits 45423 45466 +43
- Misses 12118 12120 +2
- Partials 3154 3160 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9cf3d40 to
d45a485
Compare
pkg/query/reader.go
Outdated
| resourceIDs[i] = res.ObjectID | ||
| } | ||
|
|
||
| // All resources in a DatastoreIterator share the same type. |
There was a problem hiding this comment.
is DatastoreIterator the only expected caller of this method?
more generally, maybe rephrase this to write an expectation of all callers: "it is assumed that callers of this method pass in resources that share a type". i'm also thinking that we could be defensive on this and reuse the for loop above to validate this assumption, which won't cost any extra cpu cycles
resourceIDs := make([]string, len(resources))
resourceType := resources[0].ObjectType
for i, res := range resources {
resourceIDs[i] = res.ObjectID
if res.ObjectType != resourceType {
return nil, fmt.Errorf("expected resource type %q but got %q", resourceType, res.ObjectType)
}
}There was a problem hiding this comment.
Yep, this is worth a signature change. Fixed.
pkg/query/datastore.go
Outdated
| wildcardSubject := ObjectAndRelation{ | ||
| ObjectType: subject.ObjectType, | ||
| ObjectID: WildcardObjectID, | ||
| Relation: subject.Relation, |
There was a problem hiding this comment.
wouldn't it it be a bug if subject.Relation != ""?
There was a problem hiding this comment.
for a follow up PR, can you please add more unit tests to this file? in https://app.codecov.io/gh/authzed/spicedb/blob/main/pkg%2Fquery%2Fdatastore.go i see that there are large blocks of code not covered by anything
miparnisari
left a comment
There was a problem hiding this comment.
overall LGTM, just some questions and one suggested follow-up
d45a485 to
f09d55e
Compare
tstirrat15
left a comment
There was a problem hiding this comment.
See comment, otherwise LGTM
| // LookupCaveatDefinition individually for each name. | ||
| type caveatDefinitionLookupAdapter struct{ r QueryDatastoreReader } | ||
|
|
||
| func (a caveatDefinitionLookupAdapter) LookupCaveatDefinitionsByNames( |
There was a problem hiding this comment.
Is the idea with this shim that we'd eventually have a bulk method that isn't making individual requests?
There was a problem hiding this comment.
Or uses the underlying cache, but yes, that's an eventual benefit.
c43c621 to
0aa62e6
Compare
0aa62e6 to
a5fa991
Compare
Description
Currently, there are very few calls in pkg/query direct to the datastore interface. We'd like to keep this interface minimal, in an effort to start to clean up datastores over time as we continue with query planner.
This has the added benefit of being a way to inject various testing scenarios directly with the query planner tests and benchmarks; for example, adding a slight delay on any call to simulate a network latency.