Review main Merged

81433[BUGFIX] Prevent superfluous SELECT DATABASE() statements

Christoph Lehmann CR +2 V +2 Easy +1 −1 updated 10/18/23, 09:56

Commit message

They are executed to build a descriptive cache identifier and
the database name is now received from configuration instead
firing an SQL query.

SQLite for example does not have a database name, here 'generic'
is used as fallback.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Oliver Klee +1
    • Markus Klein +1
    • Garvin Hicking +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Markus Klein +1
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 1

Review log 2937

Show 812 earlier messages
  1. Christoph Lehmann uploaded patch set 1 10/15/23, 20:16

  2. core-ci voted on patch set 1 V -1 10/15/23, 20:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47795

  3. Christoph Lehmann updated the commit message in patch set 2 V -1 10/15/23, 20:26

  4. core-ci voted on patch set 2 V -1 10/15/23, 20:34 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47796

  5. Christoph Lehmann marked it work in progress 10/15/23, 20:39

  6. Christoph Lehmann uploaded patch set 3 V -1 10/16/23, 09:12

  7. Christoph Lehmann uploaded patch set 4 10/16/23, 09:13

  8. Christoph Lehmann marked it ready for review 10/16/23, 09:14

  9. core-ci voted on patch set 3 V +1 10/16/23, 09:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47809

  10. core-ci voted on patch set 4 V +1 10/16/23, 09:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47810

  11. Markus Klein commented on patch set 4 10/16/23, 10:31

    SchemaInformation.php:42

    I think '-' and '_' should be allowed too
  12. Christoph Lehmann commented on patch set 5 V +1 10/16/23, 10:42

    Published edit on patch set 4.
  1. Christoph Lehmann commented on patch set 5 10/16/23, 10:42

    SchemaInformation.php:42 Reply

    Done
  2. core-ci voted on patch set 5 V +1 10/16/23, 10:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47815

  3. Markus Klein updated the commit message in patch set 6 V +1 10/16/23, 12:49

  4. Markus Klein voted on patch set 6 CR +1 10/16/23, 12:49

  5. core-ci voted on patch set 6 V +1 10/16/23, 13:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47823

  6. Garvin Hicking commented on patch set 6 10/16/23, 14:36

    SchemaInformation.php:44

    Is the use of $this->connection instead of $connection by purpose? It's a bit mixed now, the line below also uses the constructor parameter...?
  7. Christoph Lehmann commented on patch set 7 CR +1 V +1 10/16/23, 14:37

    Published edit on patch set 6.
  8. Christoph Lehmann commented on patch set 7 10/16/23, 14:37

    SchemaInformation.php:44 Reply

    Done
  9. core-ci voted on patch set 7 V +1 10/16/23, 14:46 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47826

  10. Markus Klein voted on patch set 7 CR +1 10/16/23, 15:04

  11. Garvin Hicking commented on patch set 7 V +1 CR +1 10/16/23, 16:20

    Works on my instance. I wonder if there's a case where 'dbname' is empty or not set, and 'path' also doesn't exist, but I could not find any such place. I like that it prevents a DB call now! :-)
  12. Stefan Bürk commented on patch set 7 CR -1 10/17/23, 11:07

    SchemaInformation.php:44

    Don't get this. The whole getParams() array is used as the second part of the identifier (hash) - meaning that a different path changes the identifier in anyway. How should this avoid superflous select database calls ? Even if two sqlite databases are used with the same name (or any other dbmns) the identifier would be distinct because of the params array hash - or not ? As path can be a full path, the identifier may be superseed the max identifier length. Not sure about that change at all. The "database" name was to distingish if a human looks into the cache entries. I guees, we should at least narror down the `path` to the basename or something like that, than the str_replace() -> preg-replace change is unneeded. TBH - not checked it out, just questioning from reading.
  13. Garvin Hicking commented on patch set 7 10/17/23, 11:15

    SchemaInformation.php:44 Reply

    Before, calling $connection->getDatabase() performed that SQL query, instead of re-using strings that existing, I believe that was the point of this. Good notice about stripping down the 'path' parameter more, but I rarely use SQLite instances, so I don't know if these use multiple SQLite files with the same filenames but in different paths (in which case the identifier would not be properly "distinguishable" for humans).
  14. Stefan Bürk commented on patch set 7 10/17/23, 11:42

    SchemaInformation.php:44 Reply

    One "sqlite" file is a database. That means, if you use multiple sqlite databases you have multiple files. Now I get the point. However, I still would avoid using the path here. My suggestion to use here would be: ```php $this->connectionIdentifier = sprintf( '%s-%s', str_replace( ['.', ':', '/', '\\', '!', '?'], '_', (string)($connection->getDatabasePlatform() instanceof SQLitePlatform ? 'main' : $connection->getParams()['dbname']) ), // hash connection params, which holds various information like host, // port etc. to get a descriptive hash for this connection. hash('xxh3', serialize($connection->getParams())) ); // or $this->connectionIdentifier = sprintf( '%s-%s', str_replace( ['.', ':', '/', '\\', '!', '?'], '_', (string)($connection->getParams()['dbname'] ?? 'unknown') ), // hash connection params, which holds various information like host, // port etc. to get a descriptive hash for this connection. hash('xxh3', serialize($connection->getParams())) ); ```
  15. Christoph Lehmann commented on patch set 7 10/17/23, 11:43

    SchemaInformation.php:44 Reply

    >Before, calling $connection->getDatabase() performed that SQL query, instead of re-using strings that existing, I believe that was the point of this. yes. >don't know if these use multiple SQLite files with the same filenames but in different paths That was my point to use the whole path. We could also leave away the whole database name and just use the hash. Don't know who is ever interested in the cache identifiers. I did it like this not to break the behaviour before that change.
  16. Garvin Hicking commented on patch set 7 10/17/23, 11:51

    SchemaInformation.php:44 Reply

    I'd opt for Stefans second solution, but probably use "generic" instead of "unknown"? Maybe in the future it not only relates to SQLite. And as Christoph says, the name of the actual cache identifieres probably don't matter much and are already unique due to hashing all parameters anyways.
  17. Stefan Bürk commented on patch set 7 10/17/23, 14:08

    SchemaInformation.php:44 Reply

    Was bascilly more a debugging things, and I look it up from time time to check if a connection has been cached already or not. For casual usages, it should not matter. Lolli and I just wanted to have something speaking related to the connection in the identifier back than when we added this SchemaInformation cache layer.
  18. Christoph Lehmann uploaded patch set 8 CR +1 V +1 10/17/23, 19:28

  19. Christoph Lehmann commented on patch set 7 10/17/23, 19:30

    SchemaInformation.php:44 Reply

    Thanks, i applied your suggestions
  20. Oliver Klee voted on patch set 8 CR +1 10/17/23, 19:32

  21. core-ci voted on patch set 8 V +1 10/17/23, 19:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47883

  22. Garvin Hicking voted on patch set 8 V +1 CR +1 10/17/23, 20:35

  23. Markus Klein voted on patch set 8 V +1 CR +1 10/17/23, 23:06

  24. Stefan Bürk commented on patch set 8 V +2 CR +2 10/18/23, 09:46

    Thanks Christoph for the patch and also adopting the suggested changes.
  25. Stefan Bürk merged patch set 9 10/18/23, 09:56