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

Add email index to contacts table and update performance test #225

Conversation

sweep-ai[bot]
Copy link
Contributor

@sweep-ai sweep-ai bot commented Oct 17, 2024

This pull request was created by Sweep to resolve the following request by @curtisdelicata:

Original Request

SQLSTATE[42000]: Syntax error or access violation: 1176 Key 'contacts_email_index' doesn't exist in table 'contacts'

Fix missing 'contacts_email_index' in Contact model and migration

Description:

The error message indicates that the 'contacts_email_index' doesn't exist in the 'contacts' table, which is causing a syntax error. We need to add this index to the Contact model and create a migration to add it to the database.

Tasks:

  • Update app/Models/Contact.php:

    • Remove or comment out the useIndex('contacts_email_index') line in the booted method
    • Add a new migration to create the missing index
  • Create a new migration file:

    • Use Artisan to generate a new migration for adding the index
    • In the migration, add the 'contacts_email_index' to the 'contacts' table
  • Update tests/Feature/ContactSearchPerformanceTest.php:

    • Modify the testDatabaseIndexPerformance method to create the index if it doesn't exist

Test:

  • Run the `Conta...

Continue chatting at https://sweep-chat-demo.vercel.app/c/a41001b2-9cb7-49de-8fc8-7adc5cb67797.

Purpose

This pull request adds an index on the email column of the contacts table to improve the performance of email-based searches. It also updates the existing ContactSearchPerformanceTest to verify the performance improvement.

Description

  1. Added a new migration AddContactsEmailIndex that creates an index on the email column of the contacts table.
  2. Updated the Contact model to remove the commented-out useIndex global scope, as the index doesn't exist yet.
  3. Updated the ContactSearchPerformanceTest to:
    • Check if the contacts_email_index index exists before the test
    • Drop the index if it exists, to ensure a fair comparison
    • Create the index after the initial test without the index
    • Measure and assert that the search with the index is faster than without the index
    • Drop the index after the test is complete

Summary

  • Updated app/Models/Contact.php to remove the commented-out useIndex global scope
  • Added a new migration database/migrations/2023_05_25_000001_add_contacts_email_index.php to create an index on the email column of the contacts table
  • Updated tests/Feature/ContactSearchPerformanceTest.php to test the performance improvement with the new index

@curtisdelicata curtisdelicata merged commit c0dc149 into main Oct 17, 2024
2 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant