#✅ - Is this expensive query

8 messages · Page 1 of 1 (latest)

crisp wagon
#

Let's assume I have the following query:


const ownersIds = [/* Array with 1k records or more */];

const ownersIdsFilter = ownersIds.map(id => {
  ownerId: { eq: id }
});


const { data: todos, errors } = await client.models.Todo.list({
  filter: {
    or: ownersIdsFilter 
  }
});

I am not feeling well about this query to be honest, and I am in favor maybe for a 1-1 relation instead!

Any advise, recommendations or tips!

remote dirge
#

are you trying filter todos of specific owners? whats your usecase?

crisp wagon
#

Indeed, that's what I am trying to do!

#

The use case like, I have a string field ownerId on Todos model that stores the user profile id! (no relationship by amplify used for now)

I need to fetch todos for user with the given ids!

I want to know how performant to do such query! with many Or s!

remote dirge
crisp wagon
#

@remote dirge thank you! yeah I am aware of this but I was wondering if doing so considered as a bad practice in contrast with explicitly having a relationship!

remote dirge
#

When working with data models, it is recommended to leverage relationships between entities. Relationships help maintain data integrity and consistency while providing performance benefits. Amplify automatically generates indexes for relationships, optimizing query performance and improving application responsiveness and scalability. Therefore, incorporating relationships into your data modeling approach is a best practice for enhancing your application's performance and efficiency.

bleak larkBOT
#

✅ - Is this expensive query