phalcon / phalcon-devtools

Phalcon Developer Tools
https://docs.phalcon.io/latest/en/devtools
Other
1.33k stars 629 forks source link

Scan the whole Database before generate one model #1524

Open crimsonskyrem opened 2 years ago

crimsonskyrem commented 2 years ago

Questions should go to https://forum.phalcon.io Documentation issues should go to https://github.com/phalcon/docs/issues

Expected and Actual Behavior

Describe what you are trying to achieve and what goes wrong.

when I run phalcon to generate some model , like user_table in my database:

phalcon model user_table

Provide output if related

it will stuck in output and no more message

Phalcon DevTools (4.2.0)

I check the database , SHOW_PROCESSLIST shows the process are checking some other tables,

SELECT DISTINCT KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.CONSTRAINT_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.CONSTRAINT_SCHEMA = KCU.CONSTRAINT_SCHEMA WHERE KCU.REFERENCED_TABLE_NAME IS NOT NULL AND KCU.CONSTRAINT_SCHEMA = DATABASE() AND KCU.TABLE_NAME = 'other_tables'

then this sql goes again to generate the model

SELECT DISTINCT KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.CONSTRAINT_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.CONSTRAINT_SCHEMA = KCU.CONSTRAINT_SCHEMA WHERE KCU.REFERENCED_TABLE_NAME IS NOT NULL AND KCU.CONSTRAINT_SCHEMA = 'my_db' AND KCU.TABLE_NAME = 'user_table'

since my database has 800+ tables, it always take a long time to generate one model

I have no idea what is this scan running for, but when I generate only one model , it should scan only this table ?

Details

Phalcon DevTools (4.2.0)

crimsonskyrem commented 2 years ago

I read this relative snippet in src/Builder/Component/Model.php:166 Now I figured out that whole schema scan mainly serves to find relations of the table which need to be generated So I was considering to add some options like "--no-relation" to skip this whole schema scan ? Is this solution acceptable ?