mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
improvement : performance of members#show and reservations#index
This commit is contained in:
parent
d197f16cd9
commit
d95e2ac56c
@ -6,6 +6,7 @@
|
||||
- Fix a bug: public availabilities (no user) was buggy (server error)
|
||||
- Fix a bug: unable to generate statistic
|
||||
- Fix a bug: rss/projects was failing with project without image
|
||||
- improvement : performance of members#show and reservations#index
|
||||
|
||||
- [TODO DEPLOY] `rails fablab:openlab:bulk_export`
|
||||
- [TODO DEPLOY] `rails fablab:openlab:bulk_update`
|
||||
|
@ -16,8 +16,10 @@ class API::ReservationsController < API::APIController
|
||||
where_clause[:reservable_id] = params[:reservable_id] if params[:reservable_id]
|
||||
|
||||
@reservations = Reservation.where(where_clause)
|
||||
.preload(:reservable, :booking_users, :tickets, { statistic_profile: { user: :profile }, slots_reservations: :slot })
|
||||
elsif params[:reservable_id] && params[:reservable_type] && (current_user.admin? || current_user.manager?)
|
||||
@reservations = Reservation.where(params.permit(:reservable_id, :reservable_type))
|
||||
.preload(:reservable, :booking_users, :tickets, { statistic_profile: { user: :profile }, slots_reservations: :slot })
|
||||
else
|
||||
@reservations = []
|
||||
end
|
||||
|
@ -10,7 +10,8 @@ json.trainings @member.trainings do |t|
|
||||
json.id t.id
|
||||
json.name t.name
|
||||
end
|
||||
json.training_reservations @member.reservations.where(reservable_type: 'Training').map(&:slots_reservations).flatten do |sr|
|
||||
reservations = @member.reservations.where(reservable_type: 'Training').preload(slots_reservations: [:slot, reservation: :reservable])
|
||||
json.training_reservations reservations.select { |r| r.reservable_type == "Training" }.map(&:slots_reservations).flatten do |sr|
|
||||
json.id sr.id
|
||||
json.start_at sr.slot.start_at
|
||||
json.end_at sr.slot.end_at
|
||||
@ -19,7 +20,7 @@ json.training_reservations @member.reservations.where(reservable_type: 'Training
|
||||
json.is_valid @member.statistic_profile.training_ids.include?(sr.reservation.reservable_id)
|
||||
json.canceled_at sr.canceled_at
|
||||
end
|
||||
json.machine_reservations @member.reservations.where(reservable_type: 'Machine').map(&:slots_reservations).flatten do |sr|
|
||||
json.machine_reservations reservations.select { |r| r.reservable_type == "Machine" }.map(&:slots_reservations).flatten do |sr|
|
||||
json.id sr.id
|
||||
json.start_at sr.slot.start_at
|
||||
json.end_at sr.slot.end_at
|
||||
@ -27,7 +28,7 @@ json.machine_reservations @member.reservations.where(reservable_type: 'Machine')
|
||||
json.reservable_type 'Machine'
|
||||
json.canceled_at sr.canceled_at
|
||||
end
|
||||
json.space_reservations @member.reservations.where(reservable_type: 'Space').map(&:slots_reservations).flatten do |sr|
|
||||
json.space_reservations reservations.select { |r| r.reservable_type == "Space" }.map(&:slots_reservations).flatten do |sr|
|
||||
json.id sr.id
|
||||
json.start_at sr.slot.start_at
|
||||
json.end_at sr.slot.end_at
|
||||
|
Loading…
x
Reference in New Issue
Block a user