PlaceOS/staff-api

Optimise bookings search

Closed this issue · 0 comments

Bookings search uses a query which may lead to heavy load:

query = Booking.query
.by_tenant(tenant.id)
.by_zones(zones)
.by_user_or_email(user_id, user_email, include_booked_by)
.booking_state(booking_state)
.created_before(created_before)
.created_after(created_after)
.is_approved(approved)
.is_rejected(rejected)
.is_checked_in(checked_in)
.by_ext(extension_data)
.where(
%("booking_start" < :ending AND "booking_end" > :starting AND "booking_type" = :booking_type),
starting: starting, ending: ending, booking_type: booking_type)
.order_by(:booking_start, :desc)
.limit(20000)

Given frequency of this operation under normal operation, it would be good to review and optimise this to improve perf and reduce infra requirements.