db icon indicating copy to clipboard operation
db copied to clipboard

Separated scheme loading from main thread.

Open kamarton opened this issue 4 years ago • 4 comments

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 -

kamarton avatar Mar 07 '20 08:03 kamarton

That would potentially hurt ability to adjust table rapidly during development, right?

samdark avatar Mar 12 '20 15:03 samdark

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

kamarton avatar Mar 28 '20 05:03 kamarton

So the following could be a solution:

  1. Create a console command that can dump schema to a file.
  2. Add ability to use the file instead of getting fresh schema from database.

samdark avatar Mar 28 '20 15:03 samdark