Closed andreievg closed 5 months ago
I've been playing around with the Apollo cache a bit and I think I understand it better now. I've been able to (finally) get the cache-and-network
policy working nicely with the list (which shows a cached version immediately, but runs a network request in the background and updates the UI if changed)
In the cases where we have multiple getReviewResponses
in quick succession, we should definitely be able to get a big improvement by getting the cache settings right. Might not need the additional endpoint even, not sure.
I would also be keen to have a look at the front-end logic and see if we can reduce the number of calls to getResponses.
Okay, so suggested structure/workflow is as follows:
/gql/review/:reviewId
gql
sub-route as a starting point for future developmentreviewId
review using request (user's) JWT auth. If no result, then user doesn't have permission so return errorreviewId
(this is the somewhat tricky bit, need to look into the best way to do this. But I think we'll need to do something along these lines, as there's too many different queries and mutations that involve review responses to hard-code logic for all of them)Regarding the additional checks we do on the GraphQL request, I think we can use something like graphql-tag to turn the query into an AST which we could write a recursive validity check function for. I'm open to a simpler way of handling this, but we need some way to handle all the different shaped queries and mutations for review responses without having to write separate logic for each one.
@andreievg once we agree on the exact solution, you okay to finish the policy improvements and I'll continue with the endpoint? I'm happy to do the bulk of this, but I'll check in with you for clarification if I encounter hurdles we haven't discussed.
Related: https://github.com/msupply-foundation/conforma-server/issues/1103
I ran demo server with large data set without row level policies, and it was very snappy, for everything, including review (apart from some delay when review was finalised, i think due to some action/triggers, 5 or so seconds, which should be acceptable).
There are a couple of things we can do in short term to improve Review Performance:
The first step is to improve row lever policy speed by re-instating changes in this PR: https://github.com/msupply-foundation/conforma-server/pull/1079, that were later remove here: https://github.com/msupply-foundation/conforma-server/commit/8a0d9e52c89cc39c8cf8c95c1aa73d19b61e4737. Due to org permissions not being matched correctly. (1 days of work)
Next step is to relocate
getReviewResponses
query to a rest endpoint. This endpoint will use user JWT to do a query to specified reviewAssignment (to make sure user has required permissions), and then use admin access to do the actual query, ignoring row level policies. (2 days of work)Ideally we would do most of the re-mapping that front end is doing, in back end (consumer focused API), but that would require quite a bit more work.