Tom Winsnes
07/19/2024, 7:16 AMSELECT * FROM recipes WHERE id IN (<list of ids from SpiceDB>)
3. Do stuff with data
This seems like an incredibly slow solution for larger more complicated queries, and also really awkward to maintain in source code, so I feel like I’m missing something fundamental here, anyone have a better approach?ecordell
07/19/2024, 1:34 PMorg
).
The times when they don't work as well is when you need complex searching and filtering over large sets. We built Materialize for that: https://authzed.com/blog/materialize-early-access - Materialize has an API that sends lists of authorized objects that you can ingest back into your own datastore to join against and filter by.Tom Winsnes
07/20/2024, 2:14 AMMatt Polzin
07/20/2024, 2:53 PMTom Winsnes
07/23/2024, 12:52 AMselect id from recipes
2. transform data to SpiceDB format (in app)
3. Bulk check against SpiceDB (in app)
4. filter out unauthorized objects (in app)
5. select * from recipes where id IN (<object ids>)
6. do stuff with dataecordell
07/23/2024, 8:06 PMselect id from recipes where description like 'potato'
, etc. And it does have the problem that if authorized resources are sparse compared to all resources, it may take time to page through all of those requests.ecordell
07/23/2024, 8:17 PM(user:evan, 123789), (user:tom, 456123)
and (123789, recipe:mushroom_soup#view), (456123, recipe:salad#view)
- the ids are internal materialize ids. You subscribe to specific permissions that you want to filter by and store those pairs in your database, and you join those two sets wherever the internal id is the same to find out what permissions you have - i.e. in this case, user:evan
can view recipe:mushroom_soup
and user:tom
can view recipe:salad
.
You can join against those tables in your own queries to pre-filter without hitting SpiceDB at all. There will be some lag between when writes happen in SpiceDB and when the results pop up in Materialize (typically a second or two, but it depends on the schema and type of change). If your application requires it (i.e. very sensitive to new-enemies, probably not a recipe application), you can be extra safe by also post-filtering via the BulkCheck apis, which unlike before won't have the risk of being sparse.ecordell
07/23/2024, 8:19 PMselect * from recipe join materialize where materialize.user = evan and materlialize.permission = view and materialize.recipe_id = recipe.id
to get the filtered listecordell
07/23/2024, 8:20 PMecordell
07/23/2024, 8:26 PMTom Winsnes
07/31/2024, 5:58 AMTom Winsnes
07/31/2024, 6:19 AMecordell
08/01/2024, 6:19 PMTom Winsnes
08/02/2024, 1:41 AMMatt Polzin
08/07/2024, 7:04 PM