Hi everyone, follow up on <https://prisma.slack.co...
# prisma-client
j
Hi everyone, follow up on https://prisma.slack.com/archives/CCWDULGUW/p1652285161791689 I've updated my schema to have an Index property on each of the window, and when I want to create one in the middle of the list, I run an update on the index of all the windows that need to be incremented by one. But that is slow. like 4125ms slow. Even using nested writes (so all the updates happen in one prisma operation), to update just a dozen object. Is there a better data modelling practice for a collection of Models where the order matter and where I want user to be able to reorder models and insert new one at any part of the list?
āœ… 1
Answering my own question: • part of the slowness was due to my DB and prisma proxy being in different continents. That's because the heroku postgres DB that was setup automatically as part of registering to prisma proxy was in the US by default whereas the rest of my stack is in europe. But more specifically, I managed to make it fast by using updateMany, in and increment:
Copy code
where: {
  id: {
    in: myListOfObjectIdsThatNeedsIncrement
  }
  data : {
    index: {
      increment: 1
    }
  }
}
the duration is now down to 400ms from my local machine, I'd expect less in prod
less than 200ms using
Copy code
houseId: house.id,
index: {
    gte: newWindow.index,
},
data: {
    index: {
        increment: 1
    }
}
j
@Johan LAJILI you can probably lower that latency further by creating indexes on the index fields in your prisma schema
šŸ‘ 1
(thats assuming you don't have indexes already)
n
You could even look at the extendedIndexes preview feature if it fits your use case
j
thanks for the protip I will give it a look