Querying related models make unnecessary requests
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
- #1801 de @regevbr — cerrado sin fusionar
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript
Línea de trabajo
Comienza leyendo lib/scope.js, especialmente el comportamiento mostrado en el commit enlazado y en el 2.x fork reportado. Reproduce la hasMany-through query con un where filter y verifica que la through-model request devuelva solo los IDs relacionados sin obtener los datos completos del related-model, mientras que la consulta final del related-model siga aplicando el filtro.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Steps to reproduce
Create a model called Book with the properties id,author,title
Add a hasMany relation between the default User model and the Book model using a through Model called UserToBook which has the following properties: userId,bookId
The relation is defined in the User model like so.
"books": {
"type": "hasMany",
"model": "Book",
"foreignKey": "userId",
"through": "UserToBook",
"keyThrough": "bookId"
},
Current Behavior
Querying the user for his books using a where filter performs 2 requests - one to the through model and one to the actual related model. The query to the through model is adding an include to the related model, which causes a fetch of a lot of data from the related model.
The reason this data is needed, is to extract the related model ids, so we can use it to filter out when performing the actual call the related model.
Expected Behavior
There is no need at all to fetch the related model data in the first call - we can simply get the ids from the through model, and use them
Link to reproduction sandbox
Working on it
Additional information
Since I'm using (sadly) loopback 2.x I have added the fix to my own fork - https://github.com/regevbr/loopback-datasource-juggler/blob/2.x/lib/scope.js
You can understand and base the fix based on the changes there
- Lenguaje dominante
- JavaScript
- Estrellas
- 279
- Forks
- 362
- Merge medio
- 21 h 14 min
- PR fusionados (30 d)
- 16
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de loopbackio/loopback-datasource-juggler
-
Breaking changes for `loopback-datasource-juggler@7` not listed anywhereQuizá libre de nuevo @dhmlau la tomó hace 158 días y no hay ningún pull request abierto. Abiertobug
loopbackio/loopback-datasource-juggler#2548 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Replace deprecated util._extend with Object.assign to ensure compatibility with modern Node.jsAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
loopbackio/loopback-datasource-juggler#2530 ·
Los mantenedores suelen responder en 1 día
-
allow empty array in createAllPosiblemente ocupada @ajay-prajapati07 la tomó hace 533 días. Abiertofeature
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
loopbackio/loopback-datasource-juggler#2409 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
loopbackio/loopback-datasource-juggler#2319 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
loopbackio/loopback-datasource-juggler#1968 ·
Los mantenedores suelen responder en 1 día
Todos los issues de loopbackio/loopback-datasource-juggler
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 63/100
anothaDev/luci-theme-vantage#143 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
kingcharleslzy-ai/dsh-purge#282 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
-
a-corriger bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
christian-raj/S-Aloha#340 ·
-
area:image documentation good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día