Total Count Support for Paginated LookupResources API #2755
-
ProblemWe're building a UI with paginated authorization resources, but users expect total counts (e.g., "Showing 1-20 of 150 groups"). The Current Workarounds
Questions
Use Case
Potential SolutionOptional fields in
Any guidance on SpiceDB's philosophy here would help with our architectural decisions. Thanks! Environment: SpiceDB v1.24.0 via authzed-py |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Unfortunately, this isn't really possible, outside of using Materialize (https://authzed.com/docs/authzed/concepts/authzed-materialize). The only way to determine the total count is to fully calculate the results, which the callers can already do. This, of course, has performance implications as you mentioned and also requires the caller to either cache the full set of results themselves (and keep them updated) or have possibly-stale counts displayed. This is, in fact, what Materialize does: it precomputes the results set(s) for the watched permission(s), so it has the data available more or less in real-time, and thus can answer these questions. Our recommendation is to not display the (possibly stale) counts, but show a "Has More" indication until the end of the list is reached. Once a user has more than a few hundred results, it often becomes fairly useless for them to have the counts, outside of running something like a "report" (which can call the full LR and usually wait). |
Beta Was this translation helpful? Give feedback.
Unfortunately, this isn't really possible, outside of using Materialize (https://authzed.com/docs/authzed/concepts/authzed-materialize).
The only way to determine the total count is to fully calculate the results, which the callers can already do. This, of course, has performance implications as you mentioned and also requires the caller to either cache the full set of results themselves (and keep them updated) or have possibly-stale counts displayed.
This is, in fact, what Materialize does: it precomputes the results set(s) for the watched permission(s), so it has the data available more or less in real-time, and thus can answer these questions.
Our recommendation is to not display the (…