-
Notifications
You must be signed in to change notification settings - Fork 0
Add batch for station routes #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| import DataLoader from 'dataloader' | ||
| import { map } from 'lodash' | ||
| import db, {aql} from '../../db' | ||
| import Route from './route' | ||
|
|
||
|
|
@@ -27,11 +29,24 @@ export const resolvers = { | |
| longitude ({ stop_lon }) { | ||
| return stop_lon | ||
| }, | ||
| routes ({ stop_id }, {from, length}) { | ||
| return db().query(aql` | ||
| routes ({ stop_id }, { from, length }) { | ||
| return RoutesByStationIdLoader.load({ stop_id, from, length }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const getRoutesByStationIds = (stopIds) => { | ||
| const { from, length } = stopIds[0] | ||
| stopIds = map(stopIds, 'stop_id') | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tu peux retourner directement
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'avais tenté cette requête mais sans succès, il ne connait pas ` `
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tu peux regarder dans les logs de la base pour voir quelle requête arrive vraiment à la base. Je pense qu'elle ne doit pas bien contenir l'objet
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai loggé cette requête côté arangodb ` `
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Les paramètres n'apparaissent pas ?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On voit que
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Petite coquille dans mon code je mappais sur
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://docs.arangodb.com/3.1/AQL/Operations/Limit.html
:/ |
||
| db().query(aql` | ||
| for stopId in ${stopIds} | ||
| let from = stopId.from | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Qu'est-ce ?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. un reste de fail :) L'impression que je peux pas variabiliser les valeur de LIMIT dans AQL... |
||
|
|
||
| let stops = ( | ||
| for stop in stops | ||
| filter stop.parent_station == ${stop_id} | ||
| filter stop.parent_station == stopId | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je crois que c'est un peu plus performant si tu fais
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alors oui mais en fait les paramètres de pagination font partie de ta clé et doivent pouvoir être différents pour chaque arrêt. Donc tu es obligé de revoir un peu ta requête et de faire un
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je suis obliger de wraper avec un 'for' ce qu'attend dataloader en retour est une |
||
| return stop.stop_id | ||
| ) | ||
|
|
||
|
|
@@ -47,15 +62,21 @@ export const resolvers = { | |
| return trip.route_id | ||
| ) | ||
|
|
||
| for route in routes | ||
| filter route.route_id in routes_of_stops | ||
| limit ${from}, ${length} | ||
| return route | ||
| `).then(cursor => cursor.all()) | ||
| } | ||
| } | ||
| let routes = ( | ||
| for route in routes | ||
| filter route.route_id in routes_of_stops | ||
| limit ${from}, ${length} | ||
| return route | ||
| ) | ||
|
|
||
| return routes | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je ne suis pas sûr que cette requête marche pour plus d'un arrêt, parce que la variable
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La requête semble fonctionner comme il faut pourtant
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oui en fait AQL n'a que faire de l'indentation. Le |
||
| `).then(cursor => cursor.all()) | ||
| .then(routes => resolve(routes)) | ||
| }); | ||
| } | ||
|
|
||
| const RoutesByStationIdLoader = new DataLoader(getRoutesByStationIds); | ||
|
|
||
| export function stationDbId (stationDtoId) { | ||
| return 'StopArea:' + stationDtoId | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Il faudrait que les paramètres de pagination puissent différents pour chaque id. Mais j'imagine que c'est pour commencer là. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui je sais pas trop comment les gérer pour le moment