[Gravity] Add defragment method to optimize tables

Review Request #1034 — Created Sept. 29, 2023 and submitted

d.cova
Lunr.Gravity
ML-744
6fd1331...
lunr

Add defragment method to optimize tables

Unit tests

  • 0
  • 0
  • 29
  • 0
  • 29
Description From Last Updated
pprkut
  1. 
      
  2. src/Lunr/Gravity/MySQL/MySQLConnection.php (Diff revision 1)
     
     
     
     

    Need error handling here, and potentially a dedicated exception

  3. src/Lunr/Gravity/SQLite3/SQLite3Connection.php (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
     

    defragment works differently for sqlite

    1. SQLite apparently automatically reuses the space, it still has a VACUUM command that seems to be the closest to what we want, should I use that?

  4. 
      
d.cova
pprkut
  1. 
      
  2. src/Lunr/Gravity/MySQL/MySQLConnection.php (Diff revisions 1 - 2)
     
     

    The preg_match is not needed. Just use the escaper.

  3. src/Lunr/Gravity/MySQL/MySQLConnection.php (Diff revisions 1 - 2)
     
     

    I'd probably go for DefragmentationException, since "optimize" is a very mysql specific term.

  4. src/Lunr/Gravity/SQLite3/SQLite3Connection.php (Diff revisions 1 - 2)
     
     

    This should be ?string, only here, not in the parent.

  5. src/Lunr/Gravity/SQLite3/SQLite3Connection.php (Diff revisions 1 - 2)
     
     

    That's the query for when $table is NULL

    1. If we want this to run we should always set table to be null inside the method

  6. 
      
d.cova
d.mendes
  1. 
      
  2. i can't find where this is used,
    is it needed?

  3. 
      
d.mendes
  1. 
      
  2. null is missing

  3. 
      
d.mendes
  1. 
      
  2. missing description and @covers
    i don't think that is the position we usually use for @param and @dataProvider

  3. 
      
d.mendes
smillernl
  1. 
      
  2. src/Lunr/Gravity/DatabaseConnection.php (Diff revision 3)
     
     

    Please add a return type

  3. It can't the file is created in 2023

  4. Let's just return if it isn't

    1. Vacuum doesn't run on specific tables at all, I suppose it can just run, no matter what parameter it gets

  5. No, the file is too new for that.

  6. 
      
d.cova
pprkut
  1. 
      
  2. src/Lunr/Gravity/MySQL/MySQLConnection.php (Diff revision 4)
     
     
     
     
     

    This doesn't actually tell us why the query failed. We do this with the logger in the DatabaseAccessObject

  3. src/Lunr/Gravity/MySQL/Tests/MySQLConnectionDefragmentTest.php (Diff revision 4)
     
     
     
     
     
     
     
     
     
     
     

    Nothing in the defragment method checks for valid table names.

  4. If we don't care about the return of the method, there's no need to mock it.

  5. Don't really care about this here. Changing the logging in the query method shouldn't cause this test to fail

  6. 
      
d.cova
smillernl
  1. 
      
  2. This shouldn't be here

  3. 
      
d.cova
smillernl
  1. 
      
  2. src/Lunr/Gravity/DatabaseConnection.php (Diff revision 6)
     
     

    This shouldn't be removed for existing files

  3. Probably good to log that passing a $table did nothing here.

  4. Shouldn't this represent the table too?

  5. 
      
d.cova
smillernl
  1. 
      
  2. The default will never be used since the parent method does not allow null.

  3. tests/phpunit.xml (Diff revision 7)
     
     
  4. 
      
d.cova
smillernl
  1. 
      
  2. Let's just make it like:

         * @param string $table This parameter is ignored when using SQLite, as VACUUM operates on the entire database.
    
  3. 
      
pprkut
  1. 
      
  2. We know the complete message here so no need to do a substring only match

  3. We can come up with a better error message here. Don't need to end the string with : ;)

  4. 
      
d.cova
smillernl
  1. Ship It!
  2. 
      
pprkut
pprkut
Review request changed

Status: Closed (submitted)

Change Summary:

Merged into master

Loading...