Skip to content

Commit

Permalink
incusd/auth/openfga: Use chunking
Browse files Browse the repository at this point in the history
Without chunking, we quickly hit the limit of 100 operation per transaction.

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Nov 28, 2023
1 parent 784ffeb commit 1824c0e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/server/auth/driver_openfga.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,27 @@ func (f *fga) updateTuples(ctx context.Context, writes []client.ClientTupleKey,
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()

opts := client.ClientWriteOptions{AuthorizationModelId: openfga.PtrString(f.authModelID)}
opts := client.ClientWriteOptions{
AuthorizationModelId: openfga.PtrString(f.authModelID),
Transaction: &client.TransactionOptions{
Disable: true,
MaxParallelRequests: 5,
MaxPerChunk: 50,
},
}

body := client.ClientWriteRequest{}

if writes != nil {
body.Writes = &writes
} else {
body.Writes = &[]client.ClientTupleKey{}
}

if deletions != nil {
body.Deletes = &deletions
} else {
body.Deletes = &[]client.ClientTupleKey{}
}

clientWriteResponse, err := f.client.Write(ctx).Options(opts).Body(body).Execute()
Expand Down

0 comments on commit 1824c0e

Please sign in to comment.