how to reduce db queries

GET /organization-os 200 in 2450ms
Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"]
Query: select "id", "name", "email", "email_verified", "image", "onboarded", "created_at", "updated_at" from "user" where "user"."id" = $1 -- params: ["lu2xgWwEaxetZPv-Rx0gC"]
Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"]
Query: select "id", "name", "email", "email_verified", "image", "onboarded", "created_at", "updated_at" from "user" where "user"."id" = $1 -- params: ["lu2xgWwEaxetZPv-Rx0gC"]
Query: select "id", "organization_id", "user_id", "role", "created_at" from "member" where "member"."user_id" = $1 limit $2 -- params: ["lu2xgWwEaxetZPv-Rx0gC", 100]
Query: select "id", "name", "slug", "logo", "created_at", "metadata" from "organization" where "organization"."id" in ($1, $2) limit $3 -- params: ["9VBA7Lr5HcerASzEw-rtG", "ht0hWzfF_NoLQ6q7VHgXj", 100]
Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"]
Query: select "id", "name", "email", "email_verified", "image", "onboarded", "created_at", "updated_at" from "user" where "user"."id" = $1 -- params: ["lu2xgWwEaxetZPv-Rx0gC"]
GET /organization-os 200 in 3796ms
GET /organization-os 200 in 2450ms
Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"]
Query: select "id", "name", "email", "email_verified", "image", "onboarded", "created_at", "updated_at" from "user" where "user"."id" = $1 -- params: ["lu2xgWwEaxetZPv-Rx0gC"]
Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"]
Query: select "id", "name", "email", "email_verified", "image", "onboarded", "created_at", "updated_at" from "user" where "user"."id" = $1 -- params: ["lu2xgWwEaxetZPv-Rx0gC"]
Query: select "id", "organization_id", "user_id", "role", "created_at" from "member" where "member"."user_id" = $1 limit $2 -- params: ["lu2xgWwEaxetZPv-Rx0gC", 100]
Query: select "id", "name", "slug", "logo", "created_at", "metadata" from "organization" where "organization"."id" in ($1, $2) limit $3 -- params: ["9VBA7Lr5HcerASzEw-rtG", "ht0hWzfF_NoLQ6q7VHgXj", 100]
Query: select "id", "expires_at", "token", "created_at", "updated_at", "ip_address", "user_agent", "user_id", "active_organization_id" from "session" where "session"."token" = $1 -- params: ["vVruXo2YbncR1OAb7vQE5UeyHlisPWHG"]
Query: select "id", "name", "email", "email_verified", "image", "onboarded", "created_at", "updated_at" from "user" where "user"."id" = $1 -- params: ["lu2xgWwEaxetZPv-Rx0gC"]
GET /organization-os 200 in 3796ms
this is the number of queries being run by my middleware to check for whether the user is auth'd and onboarded and then fetch its active org slug and redirect it there. how can i optimse this? cant use redis as there is no utility to explicitly invalidate redis keys whuch is required by me for my specific use case
1 Reply
The Untraceable
The Untraceable2mo ago
Don't auth in middleware I've been told, instead do it per page/route Most check you can do is a presence check of the session cookie

Did you find this page helpful?