Hi team,
# spicedb
g
Hi team, I'm using readRelationships and I would like to optimize for some bulk endpoint and do it in batch. Is there anything like "readRelationshipsBulk" where I can send a list of RelationshipFilters and it returns the sum of all of those filters. Say, I want all relationships of a specific type for both ResourceId A and ResourceId B, and only perform a network call. From a pure SQL perspective, this should be super easy for one type of relation and different object ids, something like
select * from relation_tuple where object_id = any (....) and relation = ?
. But even when combining several relations, it could be done in one query, at least for cockroachdb. Something like:
select * from relation_tuple where (object_id, relation, userset_object_id) = any(?)
and the ? contains an array of [custom types](https://www.cockroachlabs.com/docs/stable/create-type). In this particular case, I have a tree of shared directories (more like a forest) in spicedb. To avoid the problem with double state in a different db, I want to get not only the data available, but the tree itself. I was thinking on doing two calls: give me my resources, give me the parents for all those. With that I would have enough information to return the whole tree of directories. Cheers
v
👋This has been requested before in https://github.com/authzed/spicedb/issues/2160
a workaround would be to have a common prefix to the things you want to read in bulk, and use
https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.RelationshipFilter.optional_resource_id_prefix
and as a side note, you can also use the bulk export API, which supports the same `RelationshipFilter`: https://buf.build/authzed/api/docs/main:authzed.api.v1#authzed.api.v1.BulkExportRelationshipsRequest
g
Hi @vroldanbet , thanks, I've added a comment there on how it could be done for heterogeneous requests as well in only one query
y
also what's the use case? i personally treat readrels as an escape hatch and bookkeeping tool rather than something that i'd want to call in the critical path.