permitio/permit-golang

Optimize FilterObjects function: Reduce API calls with filtering endpoint

Closed this issue · 3 comments

The Problem :

The current implementation of FilterObjects in the Permit.io SDK iterates through each provided resource and performs an individual CheckRequest for authorization. This can lead to a significant number of API calls, especially when dealing with large datasets.

Proposed Improvement:

I propose an alternative approach that utilizes a single filtering API endpoint provided by Permit.io (if available) or a new endpoint that can filter resources based on user, action, context, and resource attributes.

Benefits:

  • Reduced API calls: Minimize network overhead and improve overall performance.
  • Potential code reduction: Streamline the logic by eliminating the need for individual Check requests.

Current behavior :

func (e *PermitEnforcer) FilterObjects(user User, action Action, context map[string]string, resources ...ResourceI) ([]ResourceI, error) {
    requests := make([]CheckRequest, len(resources))
    for i, resource := range resources {
        // ... (code for building CheckRequest objects)
        requests[i] = *NewCheckRequest(user, action, permitResource, context)
    }
    results, err := e.BulkCheck(requests...)
    // ... (rest of the function logic)
}

@obsd please create a ticket for this

@orweis any updates ?

A ticket was created, but we haven't prioritized this for work yet.

Taking a closer look now, I actually see the code already does exactly what you are asking. NewCheckRequest doesn't perform a check but only seralizes it as JSON. All the requests are sent at once in the Bulk check call.

Have you experienced any performance or networking issues that led to the creation of this ticket?

CC: @omer9564 , @obsd