Requests timeout when database has 100k+ records and table has filters

Issue Description: What’s happening?

We have a notifications table in production with 160k+ records that has a structure like this:

Attribute Type
read Boolean
user User Table
agency Agency Table

The app we are developing is a multi-tenant app where a user can be in many agencies and notifications are filtered by those terms.

We are also using permissions to filter who can perform actions on the tables

read

{
  "user": {
    "id": {
      "equals": "__loggedInUserId"
    }
  }
}

update

{
  "agency": {
    "agencyAgencyUserRelation": {
      "some": {
        "user": {
          "id": {
            "equals": "__loggedInUserId"
          }
        }
      }
    }
  }
}

With this beign said, we have a “Mark all notifications as read” button that executes a notificationsUpdateByFilter mutation that updates notifications to read: false

mutation (
  $data: { 
    set: { 
      read: true 
    } 
  }, 
  $filter: { 
    agency: {
      id: { equals: "<agency-id>" }
    },
    user: {
      id: { equals: "<user-id>" }
    },
    read: {
      equals: false
    }
  }
) {
  notificationUpdateByFilter(data: $data, filter: $filter) {
    count
  }
}

The problem is that the requests takes a really long time to respond and sometimes even throws an error on CORS (With i understand as a timeout)

Captura%20de%20pantalla%20de%202021-06-07%2015-19-58

We think is a performance issue with the permission engine because if we disable the permissions the app executes the update really fast in comparison

With permissions

Without permissions

Hello!

Do you use field permissions?

Lada Kokotova | Technicals Support Engineer

No, we are not currently using field permissions

Hello!

I’ve got your problem. We will let you know when we will understand why this is happening.

Lada Kokotova | Technical Support Engineer