codestudiohq / laravel-totem

Manage Your Laravel Schedule From A Web Dashboard
MIT License
1.8k stars 224 forks source link

Is that really necessary to check 'tasks' table every time? #127

Closed chao closed 5 years ago

chao commented 5 years ago

Our DB operator noticed there is tons of query on information_schema.tables (SELECT * FROM information_schema.tables WHERE table_schema=? and table_name='tasks') which are caused by laravel-totem.

After digging the code, in the TotemServiceProvider.php you check the 'tasks' table existence every time. Is this really necessary?

qschmick commented 5 years ago

This check is in place to ensure the service isn't booted if the migration hasn't run yet to create the base table. An issue arose in the past where a new project include totem and had immediate failures as the migrations weren't run. We should be able to wrap that check with some caching to reduce that select overhead.

chao commented 5 years ago

Yes, if the table wasn't correctly created, an exception will be thrown in ConsoleServiceProvider, right?

Maybe you can just wrap the following code with try... catch...:

$tasks = app('totem.tasks')->findAllActive();
qschmick commented 5 years ago

@chao See PR 131