db
db copied to clipboard
Separated scheme loading from main thread.
What steps will reproduce the problem?
Schema loading on the main thread is problematic in several ways (like yii2):
- block main thread, increase response delay
- this is particularly problematic as databases do not have an RFC on how long the schema loading response in 1ms, 100ms, 10sec... for example https://github.com/yiisoft/yii2/issues/17444
- not really suitable for event based updates (for example after deploy)
- cache TTL problems
- with large TTL, the change is noticed slowly
- with small TTL, a lot of updates are unnecessary
What is the expected result?
- The schema load can be called at any time, regardless of the main thread
I suggests
The best solution would be to generate the table schema to PHP code (for example one class/table).
- not require cache (no connection and loading delay)
- generation is event-based (for example, after generating the yii3 configuration)
Q | A |
---|---|
Version | 3.0.x-dev |
PHP version | - |
Operating system | - |
That would potentially hurt ability to adjust table rapidly during development, right?
That would potentially hurt ability to adjust table rapidly during development, right?
Partially. Another problem is that schema requests are executed during the HTTP request, thereby slowing down the HTTP response. This is a problem in yii2: https://github.com/yiisoft/yii2/issues/17444.
Of course, it would also be useful if the changes made to the code or database could be easily checked in all states without having to turn on / off the schema cache in the config:
- actual code + new database
- new code + actual database
- new code + new database
So the following could be a solution:
- Create a console command that can dump schema to a file.
- Add ability to use the file instead of getting fresh schema from database.