Skip to content
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

[app_handlers.go] appGetRides #1

Open
Ryoga-exe opened this issue Dec 8, 2024 · 0 comments
Open

[app_handlers.go] appGetRides #1

Ryoga-exe opened this issue Dec 8, 2024 · 0 comments
Labels

Comments

@Ryoga-exe
Copy link
Contributor

isucon14/go/app_handlers.go

Lines 214 to 259 in bb4371c

for _, ride := range rides {
status, err := getLatestRideStatus(ctx, tx, ride.ID)
if err != nil {
writeError(w, http.StatusInternalServerError, err)
return
}
if status != "COMPLETED" {
continue
}
fare, err := calculateDiscountedFare(ctx, tx, user.ID, &ride, ride.PickupLatitude, ride.PickupLongitude, ride.DestinationLatitude, ride.DestinationLongitude)
if err != nil {
writeError(w, http.StatusInternalServerError, err)
return
}
item := getAppRidesResponseItem{
ID: ride.ID,
PickupCoordinate: Coordinate{Latitude: ride.PickupLatitude, Longitude: ride.PickupLongitude},
DestinationCoordinate: Coordinate{Latitude: ride.DestinationLatitude, Longitude: ride.DestinationLongitude},
Fare: fare,
Evaluation: *ride.Evaluation,
RequestedAt: ride.CreatedAt.UnixMilli(),
CompletedAt: ride.UpdatedAt.UnixMilli(),
}
item.Chair = getAppRidesResponseItemChair{}
chair := &Chair{}
if err := tx.GetContext(ctx, chair, `SELECT * FROM chairs WHERE id = ?`, ride.ChairID); err != nil {
writeError(w, http.StatusInternalServerError, err)
return
}
item.Chair.ID = chair.ID
item.Chair.Name = chair.Name
item.Chair.Model = chair.Model
owner := &Owner{}
if err := tx.GetContext(ctx, owner, `SELECT * FROM owners WHERE id = ?`, chair.OwnerID); err != nil {
writeError(w, http.StatusInternalServerError, err)
return
}
item.Chair.Owner = owner.Name
items = append(items, item)
}

@Ryoga-exe Ryoga-exe added the N+1 label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant