Hey guys, i'm having trouble using nested queries ...
# orm-help
p
Hey guys, i'm having trouble using nested queries - my db and server are hosted in the same city so it's not because of latency My schema looks like this:
Copy code
model Profile {
  id              String?     @unique
  username        String      @id
  is_private      Boolean?
  is_verified     Boolean?
  full_name       String?
  biography       String?
  profile_pic_url String?
  post_amount     Int?
  follower        Int?
  following       Int?
  imageTags       ImageTags[]

  nodes           Image[] // this is the slow relation

  SearchProfiles SearchProfiles[]
  @@map("profile")
}

model Image {
  id              String           @id
  thumbnail       String
  shortcode       String           @unique
  liked           Int
  comment_count   Int
  engagement_rate Float?
  day             Int?
  hour            Int?
  date            String
  caption         String?

  profile         Profile?         @relation(fields: [profileUsername], references: [username])
  profileUsername String?

  hashtag         Hashtag?         @relation(fields: [hashtagName], references: [name])
  hashtagName     String?
  location        Location?        @relation(fields: [locationId], references: [id])
  locationId      String?
  imageHashtags   ImageHashtags[]
  imageTags       ImageTags[]
  imageLocations  ImageLocations[]

  @@map("image")
}
if i run this query, it takes about 4-5 seconds to give me the results
Copy code
const user = await prisma.profile.findUnique({
    where: {
      username,
    },
    include: {
      nodes: true,
    },
  });
if i run it without the include it takes around 200ms
Copy code
const user = await prisma.profile.findUnique({
     where: {
      username,
    },
  });
the profile table has around 370k entries and and image table around 620k