-
Notifications
You must be signed in to change notification settings - Fork 2
fix(stats): filter registration stats by SummitAttendeeTicket.SummitID #535
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
Open
smarcet
wants to merge
1
commit into
main
Choose a base branch
from
fix/registration-stats-summitid-and-indexes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?php namespace Database\Migrations\Model; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| /** | ||
| * Class Version20260429120000 | ||
| * @package Database\Migrations\Model | ||
| * | ||
| * Approach D / D-half-2: adds 4 composite indexes that make the registration-stats | ||
| * queries fast after the D-half-1 SQL rewrite removes the SummitOrder join and filters | ||
| * on SummitAttendeeTicket.SummitID directly. | ||
| * | ||
| * Production deployment note: | ||
| * MySQL 8+ runs ADD INDEX with ALGORITHM=INPLACE, LOCK=NONE by default (non-unique indexes). | ||
| * For pre-MySQL-8 production, run via pt-online-schema-change or gh-ost instead. | ||
| */ | ||
| final class Version20260429120000 extends AbstractMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return 'Approach D: add composite indexes for registration-stats performance (IDX_SummitAttendeeTicket_Stats, IDX_SummitAttendeeTicket_BoughtDate, IDX_SummitAttendee_HallCheckIn, IDX_SummitAttendee_VirtualCheckIn)'; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| $ticketIndexes = $this->sm->listTableIndexes('SummitAttendeeTicket'); | ||
| $attendeeIndexes = $this->sm->listTableIndexes('SummitAttendee'); | ||
|
|
||
| if (!array_key_exists('IDX_SummitAttendeeTicket_Stats', $ticketIndexes)) { | ||
| $this->addSql( | ||
| 'ALTER TABLE SummitAttendeeTicket ADD INDEX IDX_SummitAttendeeTicket_Stats (SummitID, Status, IsActive)' | ||
| ); | ||
| } | ||
|
|
||
| if (!array_key_exists('IDX_SummitAttendeeTicket_BoughtDate', $ticketIndexes)) { | ||
| $this->addSql( | ||
| 'ALTER TABLE SummitAttendeeTicket ADD INDEX IDX_SummitAttendeeTicket_BoughtDate (SummitID, Status, IsActive, TicketBoughtDate)' | ||
| ); | ||
| } | ||
|
|
||
| if (!array_key_exists('IDX_SummitAttendee_HallCheckIn', $attendeeIndexes)) { | ||
| $this->addSql( | ||
| 'ALTER TABLE SummitAttendee ADD INDEX IDX_SummitAttendee_HallCheckIn (SummitID, SummitHallCheckedIn, SummitHallCheckedInDate)' | ||
| ); | ||
| } | ||
|
|
||
| if (!array_key_exists('IDX_SummitAttendee_VirtualCheckIn', $attendeeIndexes)) { | ||
| $this->addSql( | ||
| 'ALTER TABLE SummitAttendee ADD INDEX IDX_SummitAttendee_VirtualCheckIn (SummitID, SummitVirtualCheckedInDate)' | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| $ticketIndexes = $this->sm->listTableIndexes('SummitAttendeeTicket'); | ||
| $attendeeIndexes = $this->sm->listTableIndexes('SummitAttendee'); | ||
|
|
||
| if (array_key_exists('IDX_SummitAttendeeTicket_Stats', $ticketIndexes)) { | ||
| $this->addSql('ALTER TABLE SummitAttendeeTicket DROP INDEX IDX_SummitAttendeeTicket_Stats'); | ||
| } | ||
|
|
||
| if (array_key_exists('IDX_SummitAttendeeTicket_BoughtDate', $ticketIndexes)) { | ||
| $this->addSql('ALTER TABLE SummitAttendeeTicket DROP INDEX IDX_SummitAttendeeTicket_BoughtDate'); | ||
| } | ||
|
|
||
| if (array_key_exists('IDX_SummitAttendee_HallCheckIn', $attendeeIndexes)) { | ||
| $this->addSql('ALTER TABLE SummitAttendee DROP INDEX IDX_SummitAttendee_HallCheckIn'); | ||
| } | ||
|
|
||
| if (array_key_exists('IDX_SummitAttendee_VirtualCheckIn', $attendeeIndexes)) { | ||
| $this->addSql('ALTER TABLE SummitAttendee DROP INDEX IDX_SummitAttendee_VirtualCheckIn'); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <?php namespace Tests\Migrations; | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| use Illuminate\Support\Facades\DB; | ||
| use Tests\BrowserKitTestCase; | ||
|
|
||
| /** | ||
| * RED test (Approach D / D-half-2): | ||
| * Asserts the 4 composite indexes introduced by the Approach D migration exist in the schema. | ||
| * FAILS today (migration not yet written). PASSES after Task 2 adds the migration. | ||
| * | ||
| * Class RegistrationStatsIndexesTest | ||
| * @package Tests\Migrations | ||
| */ | ||
| final class RegistrationStatsIndexesTest extends BrowserKitTestCase | ||
| { | ||
| /** | ||
| * Asserts that all 4 Approach D composite indexes are present in the schema. | ||
| * Relies on BrowserKitTestCase running `doctrine:migrations:migrate` before tests, | ||
| * so the new migration is applied automatically once the file is added. | ||
| */ | ||
| public function testRequiredCompositeIndexesExistAfterMigration(): void | ||
| { | ||
| $required = [ | ||
| 'SummitAttendeeTicket' => [ | ||
| 'IDX_SummitAttendeeTicket_Stats', | ||
| 'IDX_SummitAttendeeTicket_BoughtDate', | ||
| ], | ||
| 'SummitAttendee' => [ | ||
| 'IDX_SummitAttendee_HallCheckIn', | ||
| 'IDX_SummitAttendee_VirtualCheckIn', | ||
| ], | ||
| ]; | ||
|
|
||
| $missing = []; | ||
| foreach ($required as $tableName => $indexNames) { | ||
| foreach ($indexNames as $indexName) { | ||
| $rows = DB::connection('model')->select( | ||
| "SELECT INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS | ||
| WHERE TABLE_SCHEMA = DATABASE() | ||
| AND TABLE_NAME = ? | ||
| AND INDEX_NAME = ? | ||
| LIMIT 1", | ||
| [$tableName, $indexName] | ||
| ); | ||
| if (empty($rows)) { | ||
| $missing[] = "{$tableName}.{$indexName}"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $this->assertEmpty( | ||
| $missing, | ||
| 'The following Approach D composite indexes are missing — ' . | ||
| 'ensure the migration (Version20260429<timestamp>.php) was created and applied: ' . | ||
| implode(', ', $missing) | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🌐 Web query:
In Doctrine DBAL, does SchemaManager::listTableIndexes() return an array keyed by normalized/lowercased index names, making case-sensitive array_key_exists checks with mixed-case index names unreliable?💡 Result:
Yes, in Doctrine DBAL, SchemaManager::listTableIndexes returns an array of Index objects keyed by normalized (lowercased) index names. This makes case-sensitive array_key_exists checks with mixed-case index names unreliable, as the keys are always lowercase regardless of the actual database index name casing.
Citations:
🏁 Script executed:
Repository: OpenStackweb/summit-api
Length of output: 96
🏁 Script executed:
Repository: OpenStackweb/summit-api
Length of output: 2726
Normalize index-name lookups before
array_key_exists.Doctrine DBAL returns index arrays keyed by lowercased names. Case-sensitive lookups with mixed-case index names will always fail, causing guards to be ineffective:
up()may attempt duplicateADD INDEXoperations, anddown()may skipDROP INDEXoperations.Suggested fix
🤖 Prompt for AI Agents