kodeine / laravel-meta

Fluent Meta Data for Eloquent Models, as if it is a property on your model
MIT License
400 stars 90 forks source link

cache hasColumn to prevent executing duplicate queries #79

Closed siamak2 closed 4 years ago

siamak2 commented 4 years ago

Hi I was reviewing executed queries in telescope and noticed there are duplicate queries like this:

select column_name as column_name from information_schema.columns where table_schema = 'db_name' and table_name = 'table_name'

so I traced the query and saw this: https://github.com/kodeine/laravel-meta/blob/052098ba5934729b717adb0ce941ad38f2889318/src/Kodeine/Metable/Metable.php#L429 which is called every time I try to set new attribute to the model and executes that query every time. so this PR will cache the query result and prevents executing same query multiple times.

kodeine commented 4 years ago

Thank you