Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
Improve check-in list query performance (#417)
Dave Earleycf01507affd4
diff --git a/backend/app/Repository/Eloquent/CheckInListRepository.php b/backend/app/Repository/Eloquent/CheckInListRepository.phpindex e3259a110..2ea368235 100644--- a/backend/app/Repository/Eloquent/CheckInListRepository.php+++ b/backend/app/Repository/Eloquent/CheckInListRepository.php@@ -5,7 +5,6 @@ namespace HiEvents\Repository\Eloquent;use HiEvents\DomainObjects\CheckInListDomainObject;use HiEvents\DomainObjects\Generated\CapacityAssignmentDomainObjectAbstract;use HiEvents\DomainObjects\Generated\CheckInListDomainObjectAbstract;-use HiEvents\DomainObjects\Status\AttendeeStatus;use HiEvents\Http\DTO\QueryParamsDTO;use HiEvents\Models\CheckInList;use HiEvents\Repository\DTO\CheckedInAttendeesCountDTO;@@ -33,15 +32,24 @@ class CheckInListRepository extends BaseRepository implements CheckInListRepositSELECT attendee_id, check_in_list_idFROM attendee_check_insWHERE deleted_at IS NULL+ AND check_in_list_id = :check_in_list_idGROUP BY attendee_id, check_in_list_id),valid_attendees AS (- SELECT a.id, tcil.check_in_list_id+ SELECT a.id, pcil.check_in_list_idFROM attendees a- JOIN product_check_in_lists tcil ON a.product_id = tcil.product_id+ JOIN product_check_in_lists pcil ON a.product_id = pcil.product_id+ JOIN orders o ON a.order_id = o.id+ JOIN check_in_lists cil ON pcil.check_in_list_id = cil.id+ JOIN event_settings es ON cil.event_id = es.event_idWHERE a.deleted_at IS NULL- AND tcil.deleted_at IS NULL- AND a.status in ('ACTIVE', 'AWAITING_PAYMENT')+ AND pcil.deleted_at IS NULL+ AND pcil.check_in_list_id = :check_in_list_id+ AND (+ (es.allow_orders_awaiting_offline_payment_to_check_in = true AND a.status in ('ACTIVE', 'AWAITING_PAYMENT') AND o.status IN ('COMPLETED', 'AWAITING_OFFLINE_PAYMENT'))+ OR+ (es.allow_orders_awaiting_offline_payment_to_check_in = false AND a.status = 'ACTIVE' AND o.status = 'COMPLETED')+ ))SELECTcil.id AS check_in_list_id,@@ -67,22 +75,30 @@ class CheckInListRepository extends BaseRepository implements CheckInListRepositpublic function getCheckedInAttendeeCountByIds(array $checkInListIds): Collection{$placeholders = implode(',', array_fill(0, count($checkInListIds), '?'));- $attendeeActiveStatus = AttendeeStatus::ACTIVE->name;$sql = <<<SQLWITH valid_check_ins AS (SELECT attendee_id, check_in_list_idFROM attendee_check_insWHERE deleted_at IS NULL+ AND check_in_list_id IN ($placeholders)GROUP BY attendee_id, check_in_list_id),valid_attendees AS (- SELECT a.id, tcil.check_in_list_id+ SELECT a.id, pcil.check_in_list_idFROM attendees a- JOIN product_check_in_lists tcil ON a.product_id = tcil.product_id+ JOIN product_check_in_lists pcil ON a.product_id = pcil.product_id+ JOIN orders o ON a.order_id = o.id+ JOIN check_in_lists cil ON pcil.check_in_list_id = cil.id+ JOIN event_settings es ON cil.event_id = es.event_idWHERE a.deleted_at IS NULL- AND tcil.deleted_at IS NULL- AND a.status = '$attendeeActiveStatus'+ AND pcil.deleted_at IS NULL+ AND pcil.check_in_list_id IN ($placeholders)+ AND (+ (es.allow_orders_awaiting_offline_payment_to_check_in = true AND a.status IN ('ACTIVE', 'AWAITING_PAYMENT') AND o.status IN ('COMPLETED', 'AWAITING_OFFLINE_PAYMENT'))+ OR+ (es.allow_orders_awaiting_offline_payment_to_check_in = false AND a.status = 'ACTIVE' AND o.status = 'COMPLETED')+ ))SELECTcil.id AS check_in_list_id,@@ -96,7 +112,7 @@ class CheckInListRepository extends BaseRepository implements CheckInListRepositGROUP BY cil.id;SQL;- $query = $this->db->select($sql, $checkInListIds);+ $query = $this->db->select($sql, array_merge($checkInListIds, $checkInListIds, $checkInListIds));return collect($query)->map(static fn($item) => new CheckedInAttendeesCountDTO(diff --git a/backend/database/migrations/2025_03_07_160427_add_missing_indexes.php b/backend/database/migrations/2025_03_07_160427_add_missing_indexes.phpnew file mode 100644index 000000000..325cbb21d--- /dev/null+++ b/backend/database/migrations/2025_03_07_160427_add_missing_indexes.php@@ -0,0 +1,45 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration {+ public function up(): void+ {+ Schema::table('product_check_in_lists', static function (Blueprint $table) {+ $table->index('check_in_list_id');+ });++ Schema::table('attendees', static function (Blueprint $table) {+ $table->index('order_id');+ });++ Schema::table('orders', static function (Blueprint $table) {+ $table->index('short_id');+ });++ Schema::table('organizers', static function (Blueprint $table) {+ $table->index('account_id');+ });+ }++ public function down(): void+ {+ Schema::table('product_check_in_lists', static function (Blueprint $table) {+ $table->dropIndex(['check_in_list_id']);+ });++ Schema::table('attendees', static function (Blueprint $table) {+ $table->dropIndex(['order_id']);+ });++ Schema::table('orders', static function (Blueprint $table) {+ $table->dropIndex(['short_id']);+ });++ Schema::table('organizers', static function (Blueprint $table) {+ $table->dropIndex(['account_id']);+ });+ }+};